Skip to content

Commit

Permalink
fix nix dirty hack by hacking cc-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
SharzyL authored and sequencer committed Oct 27, 2022
1 parent 3f08a61 commit 1270e95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ object cases extends Module {
PathRef(T.ctx.dest / "linker.ld")
}
def compile: T[PathRef] = T {
os.proc(Seq("/nix/store/jfliw7lqqfchrmnb21xi5d5pmxk1lvyg-clang-14.0.6/bin/clang", "-o", name() + ".elf" ,"--target=riscv32", "-march=rv32gcv", s"-L${musl.compile().path}/lib", s"-L${compilerrt.compile().path}/lib/riscv32", "-mno-relax", s"-T${linkScript().path}") ++ allSourceFiles().map(_.path.toString)).call(T.ctx.dest)
os.proc(Seq("clang", "-o", name() + ".elf" ,"--target=riscv32", "-march=rv32gcv", s"-L${musl.compile().path}/lib", s"-L${compilerrt.compile().path}/lib/riscv32", "-mno-relax", s"-T${linkScript().path}") ++ allSourceFiles().map(_.path.toString)).call(T.ctx.dest)
os.proc(Seq("llvm-objcopy", "-O", "binary", "--only-section=.text", name() + ".elf", name())).call(T.ctx.dest)
PathRef(T.ctx.dest / name())
}
Expand Down
19 changes: 16 additions & 3 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@ let
'';
};

# nix cc-wrapper will add --gcc-toolchain to clang flags. However, when we want to use
# our custom libc and compilerrt, clang will only search these libs in --gcc-toolchain
# folder. To avoid this wierd behavior of clang, we need to remove --gcc-toolchain options
# from cc-wrapper
my-cc-wrapper = let cc = myLLVM.clang; in pkgs.runCommand "cc" {} ''
mkdir -p "$out"
cp -rT "${cc}" "$out"
chmod -R +w "$out"
sed -i 's/--gcc-toolchain=[^[:space:]]*//' "$out/nix-support/cc-cflags"
sed -i 's|${cc}|${placeholder "out"}|g' "$out"/bin/* "$out"/nix-support/*
'';

in pkgs.mkShellNoCC {
name = "vector";
buildInputs = with pkgs; [
myLLVM.clang
myLLVM.llvm
myLLVM.bintools
my-cc-wrapper

jdk mill python3
parallel protobuf ninja verilator antlr4 numactl dtc glibc_multi cmake
Expand All @@ -60,6 +72,7 @@ in pkgs.mkShellNoCC {
fmt glog
];
shellHook = ''
export NIX_CC=" "
''; # due to some cmake bug
# because we removed --gcc-toolchain from cc-wrapper, we need to add gcc lib path back
export NIX_LDFLAGS_FOR_TARGET="$NIX_LDFLAGS_FOR_TARGET -L${pkgs.gccForLibs.lib}/lib"
'';
}

0 comments on commit 1270e95

Please sign in to comment.