Skip to content

Commit 10fba61

Browse files
committed
nix
1 parent 643ddb6 commit 10fba61

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Cargo.lock
66
/examples/is13
77
*.DS_Store
88
tests/programs/deps
9+
flake.lock

examples/is13.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
//
66
// To build the "is13.c" to riscv output, you will need to install "riscv-gnu-toolchain" in your system.
77
//
8+
// Option 1: Using Nix (Recommended - quick and easy)
9+
// If you have Nix installed, you can use the provided flake.nix:
10+
//
11+
// $ nix develop
12+
//
13+
// Option 2: Building from source (takes ~1 hour)
14+
//
815
// $ git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
916
// $ cd riscv-gnu-toolchain
1017
// $ mkdir build && cd build
1118
// $ ../configure --prefix=/opt/riscv --with-arch=rv64imac
1219
// $ make
1320
//
14-
// On my ubuntu machine, it takes 1 hours. Sad.
15-
//
1621
// Then, you can build "is13.c" by "riscv64-unknown-elf-gcc"
1722
//
1823
// $ riscv64-unknown-elf-gcc -o is13 is13.c

flake.nix

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
description = "CKB VM development environment with RISC-V toolchain";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
14+
# RISC-V toolchain
15+
riscv-toolchain = pkgs.pkgsCross.riscv64-embedded.buildPackages;
16+
in
17+
{
18+
devShells.default = pkgs.mkShell {
19+
buildInputs = with pkgs; [
20+
# RISC-V cross-compiler toolchain
21+
riscv-toolchain.gcc
22+
riscv-toolchain.binutils
23+
24+
# Rust toolchain (already in the project via rust-toolchain file)
25+
cargo
26+
rustc
27+
rustfmt
28+
clippy
29+
30+
# Build tools
31+
gnumake
32+
pkg-config
33+
34+
# Optional: useful for development
35+
gcc
36+
gdb
37+
file
38+
hexdump
39+
40+
# For running the build scripts
41+
bash
42+
];
43+
44+
shellHook = ''
45+
echo "CKB VM Development Environment"
46+
echo "================================"
47+
echo ""
48+
echo "RISC-V toolchain available:"
49+
echo " riscv64-none-elf-gcc --version"
50+
riscv64-none-elf-gcc --version | head -n1
51+
echo ""
52+
echo "To compile the is13 example:"
53+
echo " riscv64-none-elf-gcc -o examples/is13 examples/is13.c"
54+
echo ""
55+
echo "To run the example:"
56+
echo " cargo run --example is13 13"
57+
echo ""
58+
'';
59+
60+
# Environment variables
61+
RISCV_CC = "riscv64-none-elf-gcc";
62+
RISCV_LD = "riscv64-none-elf-ld";
63+
RISCV_OBJCOPY = "riscv64-none-elf-objcopy";
64+
RISCV_OBJDUMP = "riscv64-none-elf-objdump";
65+
};
66+
});
67+
}

0 commit comments

Comments
 (0)