Skip to content

Commit 040ca18

Browse files
authored
Merge pull request #7 from EspressoSystems/ma/nix-env-fixes
Nix build on linux
2 parents 6f174fc + 0843ea6 commit 040ca18

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ clean:
156156
rm -f arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/*.a
157157
@rm -rf contracts/build contracts/cache solgen/go/
158158
@rm -f .make/*
159+
# Ensure lib64 is a symlink to lib
160+
mkdir -p $(output_root)/lib
161+
ln -s lib $(output_root)/lib64
159162

160163
docker:
161164
docker build -t nitro-node-slim --target nitro-node-slim .

flake.nix

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
# Prevent cargo aliases from using programs in `~/.cargo` to avoid conflicts
4141
# with rustup installations.
4242
export CARGO_HOME=$HOME/.cargo-nix
43+
export DOCKER_BUILDKIT=1
44+
45+
# Create a target directory and ensure lib64 is a symlink to lib.
46+
# Individual build steps may target either directory and later
47+
# create the symlink making some build outputs inaccessible.
48+
mkdir -p target/lib
49+
ln -sf lib target/lib64
4350
''
4451
+ pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
4552
# Fix docker-buildx command on OSX. Can we do this in a cleaner way?
@@ -53,11 +60,16 @@
5360
{
5461
# This shell is only used for one make recipe because the other
5562
# shell is not able to build one recipe and we haven't managed to
56-
# come up with a dev shell that works for everything.
63+
# come up with a dev shell that works for everything on OSX.
5764
#
5865
# nix develop .#wasm -c make build-wasm-libs
5966
#
6067
# After that, the other shell can be used to run `make build`.
68+
#
69+
# With nix the `clang` command is a wrapper that does not understand
70+
# some of the arguments that are passed to it during the build. This
71+
# dev shell uses the unwrapped clang command and sets the include
72+
# directory manually via `CPATH`.
6173
wasm = pkgs.mkShell {
6274
# By default clang-unwrapped does not find its resource dir. See
6375
# https://discourse.nixos.org/t/why-is-the-clang-resource-dir-split-in-a-separate-package/34114
@@ -79,14 +91,24 @@
7991
export PATH="${pkgs.llvmPackages_16.clang-unwrapped}/bin:$PATH"
8092
'';
8193
};
82-
default = pkgs.mkShell {
8394

84-
packages = with pkgs; [
95+
# mkShell brings in a `cc` that points to gcc, stdenv.mkDerivation from llvm avoids this.
96+
default = let llvmPkgs = pkgs.llvmPackages_16; in llvmPkgs.stdenv.mkDerivation {
97+
# By default stack protection is enabled by the clang wrapper but I
98+
# think it's not supported for wasm compilation. It causes this
99+
# error:
100+
#
101+
# Undefined stack protector symbols: __stack_chk_guard ...
102+
# in arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/extF80_div.o
103+
hardeningDisable = [ "stackprotector" ];
104+
105+
name = "espresso-nitro-dev-shell";
106+
buildInputs = with pkgs; [
85107
cmake
86108
stableToolchain
87109

88-
# llvmPackages_16.clang # provides clang without wrapper
89-
# llvmPackages_16.bintools # provides wasm-ld
110+
llvmPkgs.clang
111+
llvmPkgs.bintools # provides wasm-ld
90112

91113
go
92114
# goimports, godoc, etc.
@@ -112,9 +134,10 @@
112134
darwin.libobjc
113135
darwin.IOKit
114136
darwin.apple_sdk.frameworks.CoreFoundation
137+
] ++ lib.optionals (! stdenv.isDarwin) [
138+
glibc_multi.dev # provides gnu/stubs-32.h
115139
];
116140
inherit shellHook;
117-
RUST_SRC_PATH = "${stableToolchain}/lib/rustlib/src/rust/library";
118141
};
119142
};
120143
});

0 commit comments

Comments
 (0)