|
3 | 3 |
|
4 | 4 | inputs = { |
5 | 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; |
| 6 | + nixpkgs-circt.url = "github:NixOS/nixpkgs/nixos-25.05"; |
6 | 7 | flake-utils.url = "github:numtide/flake-utils"; |
7 | 8 | }; |
8 | 9 |
|
9 | | - outputs = { self, nixpkgs, flake-utils }: |
| 10 | + outputs = { self, nixpkgs, nixpkgs-circt, flake-utils }: |
10 | 11 | flake-utils.lib.eachDefaultSystem ( system: |
11 | 12 | let |
12 | | - pkgs = import nixpkgs { inherit system; }; |
13 | | - gccForLibs = pkgs.stdenv.cc.cc; |
| 13 | + pkgs = import nixpkgs { inherit system; config.allowUnfree = true; }; |
| 14 | + circt = (import nixpkgs-circt { inherit system; }).circt; |
| 15 | + pkgsRV = pkgs.pkgsCross.riscv64; |
| 16 | + targetLlvmLibraries = pkgsRV.llvmPackages_21; |
14 | 17 | in rec { |
15 | 18 |
|
16 | | - defaultPackage = pkgs.stdenv.mkDerivation { |
17 | | - name = "llvm"; |
| 19 | + defaultPackage = packages.toolchain; |
18 | 20 |
|
19 | | - dontUnpack = true; |
| 21 | + packages.toolchain = with pkgsRV; (wrapCCWith rec { |
| 22 | + cc = (targetLlvmLibraries.clang-unwrapped.override { |
| 23 | + src = ./.; |
| 24 | + libllvm = (targetLlvmLibraries.libllvm.override { src = ./.; }); |
| 25 | + }); |
| 26 | + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. |
| 27 | + libcxx = null; |
| 28 | + extraPackages = [ targetLlvmLibraries.compiler-rt ]; |
| 29 | + extraBuildCommands = '' |
| 30 | + rsrc="$out/resource-root" |
| 31 | + mkdir "$rsrc" |
| 32 | + ln -s "${lib.getLib cc}/lib/clang/*/include" "$rsrc" |
| 33 | + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags |
| 34 | + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" |
| 35 | + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" |
| 36 | + ''; |
| 37 | + }); |
20 | 38 |
|
21 | | - buildInputs = with pkgs; [ |
| 39 | + packages.sim = pkgs.stdenv.mkDerivation { |
| 40 | + name = "fck-china-sim"; |
| 41 | + # Floating derivation!!! |
| 42 | + __impure = true; |
| 43 | + |
| 44 | + src = pkgs.fetchgit { |
| 45 | + url = "https://github.com/OpenXiangShan/XiangShan.git"; |
| 46 | + rev = "0fb84f8ddbfc9480d870f72cc903ac6453c888c9"; |
| 47 | + fetchSubmodules = true; |
| 48 | + leaveDotGit = true; |
| 49 | + sha256 = "sha256-C+y//RJxI8FwYWCs8dmYLh8ZGVNCTAnRoiOVuY913Jg="; |
| 50 | + deepClone = false; |
| 51 | + }; |
| 52 | + |
| 53 | + nativeBuildInputs = with pkgs; [ |
| 54 | + mill |
| 55 | + time |
| 56 | + git |
| 57 | + espresso |
| 58 | + verilator |
22 | 59 | python3 |
23 | | - ninja |
24 | | - cmake |
25 | 60 | ]; |
26 | 61 |
|
27 | | - cmakeFlags = [ |
28 | | - "-DUSE_DEPRECATED_GCC_INSTALL_PREFIX=1" |
29 | | - "-DGCC_INSTALL_PREFIX=${pkgs.gcc}" |
30 | | - "-DC_INCLUDE_DIRS=${pkgs.stdenv.cc.libc.dev}/include" |
31 | | - "-GNinja" |
32 | | - # Debug for debug builds |
33 | | - "-DCMAKE_BUILD_TYPE=Release" |
34 | | - # inst will be our installation prefix |
35 | | - "-DCMAKE_INSTALL_PREFIX=../inst" |
36 | | - "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON" |
37 | | - # change this to enable the projects you need |
38 | | - "-DLLVM_ENABLE_PROJECTS=clang" |
39 | | - # enable libcxx* to come into play at runtimes |
40 | | - "-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi" |
41 | | - # this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need |
42 | | - "-DLLVM_TARGETS_TO_BUILD=host" |
43 | | - "-S ${self}/llvm" |
| 62 | + buildInputs = with pkgs; [ |
| 63 | + sqlite.dev |
| 64 | + zlib.dev |
| 65 | + zstd.dev |
44 | 66 | ]; |
| 67 | + |
| 68 | + buildPhase = '' |
| 69 | + runHook preBuild |
| 70 | +
|
| 71 | + # Copy sources |
| 72 | + export NOOP_HOME=$out/src |
| 73 | + echo src = $src |
| 74 | + echo NOOP_HOME = $NOOP_HOME |
| 75 | + mkdir -p $NOOP_HOME |
| 76 | + cp -r $src/* $src/.* $NOOP_HOME |
| 77 | +
|
| 78 | + # Patch shebangs |
| 79 | + chmod u+wx -R $NOOP_HOME |
| 80 | + patchShebangs --build $NOOP_HOME/scripts/ |
| 81 | +
|
| 82 | + # Build |
| 83 | + export _JAVA_OPTIONS="-XX:+UseZGC -XX:+ZUncommit -XX:ZUncommitDelay=30" |
| 84 | + FIRTOOL=${circt}/bin/firtool JVM_XMX=20G make -j8 -C $NOOP_HOME emu |
| 85 | +
|
| 86 | + runHook postBuild |
| 87 | + ''; |
| 88 | + |
| 89 | + installPhase = '' |
| 90 | + runHook preInstall |
| 91 | +
|
| 92 | + mkdir -p $out/bin |
| 93 | + chmod u+x -R $out/src/build/ |
| 94 | + cp $out/src/build/verilator-compile/emu $out/bin |
| 95 | + rm -rf $out/src |
| 96 | +
|
| 97 | + runHook postInstall |
| 98 | + ''; |
45 | 99 | }; |
46 | 100 |
|
47 | 101 | devShell = (defaultPackage.overrideAttrs (oldAttrs: { |
48 | 102 | name = "llvm-env"; |
49 | | - buildInputs = oldAttrs.buildInputs ++ (with pkgs; [ verilator ]); |
| 103 | + buildInputs = oldAttrs.buildInputs; |
50 | 104 | })); |
51 | 105 |
|
| 106 | + |
52 | 107 | }); |
53 | 108 | } |
54 | 109 |
|
0 commit comments