Skip to content

Commit f846af1

Browse files
committed
fixup: Ensure flake output equivalent to firewood-go-ethhash
1 parent 3eaf74d commit f846af1

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,12 @@ jobs:
256256
working-directory: ffi
257257
# - cgocheck2 is expensive but provides complete pointer checks
258258
# - use hash mode ethhash since the flake builds with `--features ethhash,logger`
259-
run: nix develop --command env GOEXPERIMENT=cgocheck2 TEST_FIREWOOD_HASH_MODE=ethhash go test ./... -v
259+
# - run golang outside a nix shell to validate viability without the env setup performed by a nix shell
260+
run: |
261+
GOLANG="nix run $PWD#go"
262+
cd result/ffi
263+
GOEXPERIMENT=cgocheck2 TEST_FIREWOOD_HASH_MODE=ethhash ${GOLANG} test ./...
264+
shell: bash
260265

261266
firewood-ethhash-differential-fuzz:
262267
needs: build

ffi/flake.nix

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
# To use:
2+
# To test with arbitrary firewood versions (alternative to firewood-go-ethhash):
33
# - Install nix: https://github.com/DeterminateSystems/nix-installer?tab=readme-ov-file#install-nix
4-
# - Run from ffi/ dir: `nix build .#firewood-ffi`
5-
# - Run from anywhere: `nix develop 'github:ava-labs/firewood?dir=ffi&ref=[SHA]'`
4+
# - Clone firewood locally at desired version/commit
5+
# - Build: `cd ffi && nix build`
6+
# - In your Go project: `go mod edit -replace github.com/ava-labs/firewood-go-ethhash/ffi=/path/to/firewood/ffi/result/ffi`
67

78
description = "Firewood FFI library and development environment";
89

@@ -34,6 +35,10 @@
3435
src = craneLib.path ./..;
3536
filter = path: type:
3637
(lib.hasSuffix "\.md" path) ||
38+
(lib.hasSuffix "\.go" path) ||
39+
(lib.hasSuffix "go.mod" path) ||
40+
(lib.hasSuffix "go.sum" path) ||
41+
(lib.hasSuffix "firewood.h" path) ||
3742
(craneLib.filterCargoSources path type);
3843
};
3944

@@ -64,11 +69,20 @@
6469
# Use cargo alias defined in .cargo/config.toml
6570
cargoBuildCommand = "cargo build-static-ffi";
6671

72+
# Disable tests - we only need to build the static library
73+
doCheck = false;
74+
6775
# Install the static library and header
6876
postInstall = ''
69-
mkdir -p $out/lib $out/include
70-
cp target/maxperf/libfirewood_ffi.a $out/lib/ || cp target/release/libfirewood_ffi.a $out/lib/
71-
cp ffi/firewood.h $out/include/
77+
# Create a package structure compatible with FIREWOOD_LD_MODE=STATIC_LIBS
78+
mkdir -p $out/ffi
79+
cp -R ./ffi/* $out/ffi/
80+
mkdir -p $out/ffi/libs/${pkgs.stdenv.hostPlatform.config}
81+
cp target/maxperf/libfirewood_ffi.a $out/ffi/libs/${pkgs.stdenv.hostPlatform.config}/
82+
83+
# Run go generate to switch CGO directives to STATIC_LIBS mode
84+
cd $out/ffi
85+
HOME=$TMPDIR GOTOOLCHAIN=local FIREWOOD_LD_MODE=STATIC_LIBS ${pkgs.go}/bin/go generate
7286
'';
7387

7488
meta = with lib; {
@@ -88,28 +102,26 @@
88102
default = firewood-ffi;
89103
};
90104

105+
apps.go = {
106+
type = "app";
107+
program = "${pkgs.go}/bin/go";
108+
};
109+
91110
devShells.default = craneLib.devShell {
92111
inputsFrom = [ firewood-ffi ];
93112

94113
packages = with pkgs; [
114+
firewood-ffi
95115
rustToolchain
96116
go
97117
];
98118

99119
shellHook = ''
100-
echo "Firewood FFI development environment"
101-
echo "Use 'nix build .#firewood-ffi' to build the FFI package"
102-
103-
# Set up CGO environment
104-
export CGO_LDFLAGS="-L${firewood-ffi}/lib -lfirewood_ffi -lm"
105-
export CGO_CFLAGS="-I${firewood-ffi}/include"
106-
107-
# TODO(marun) Maybe add a script?
108-
echo ""
109-
echo "To run Go tests:"
110-
echo " export GOEXPERIMENT=cgocheck2"
111-
echo " export TEST_FIREWOOD_HASH_MODE=ethhash"
112-
echo " go test ./... -v"
120+
# Ensure golang bin is in the path
121+
GOBIN="$(go env GOPATH)/bin"
122+
if [[ ":$PATH:" != *":$GOBIN:"* ]]; then
123+
export PATH="$GOBIN:$PATH"
124+
fi
113125
'';
114126
};
115127
});

0 commit comments

Comments
 (0)