-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
95 lines (88 loc) · 4.03 KB
/
Copy pathflake.nix
File metadata and controls
95 lines (88 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
description = "pops — reproducible dev shell for building the WASM bindings (ts/build-wasm.sh) and running the Next.js demo";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, rust-overlay, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
# Rust 1.95 (matches rust-toolchain.toml) plus the wasm target the
# bindings compile to.
rustToolchain = pkgs.rust-bin.stable."1.95.0".default.override {
targets = [ "wasm32-unknown-unknown" ];
};
# The wasm-bindgen CLI MUST equal Cargo.lock's wasm-bindgen (0.2.122),
# or wasm-pack aborts on a schema-version mismatch. nixpkgs currently
# ships 0.2.121, so vendor the upstream prebuilt 0.2.122 release binary
# (the route the ts/README recommends as reliable).
wasm-bindgen-cli =
let
version = "0.2.122";
triple = {
"aarch64-darwin" = "aarch64-apple-darwin";
"x86_64-darwin" = "x86_64-apple-darwin";
"x86_64-linux" = "x86_64-unknown-linux-musl";
"aarch64-linux" = "aarch64-unknown-linux-gnu";
}.${system};
hashes = {
"aarch64-darwin" = "sha256-Nr6tyGxcAsURoVLo/CxjhQZGiH6X3JSuBFU2QPg56Ag=";
"x86_64-darwin" = pkgs.lib.fakeHash; # TODO: fill on first x86_64-darwin use
"x86_64-linux" = "sha256-Eio/4uqcbj6JtQ5C3Ro0bkmfP2WlSq4LTq62WBOdHg4=";
"aarch64-linux" = "sha256-HAsvBHHnc/I2n+tk5MoY8rRfq/mZbVVCWzTBumrnyJ8=";
};
in
pkgs.stdenvNoCC.mkDerivation {
pname = "wasm-bindgen-cli";
inherit version;
src = pkgs.fetchurl {
url = "https://github.com/rustwasm/wasm-bindgen/releases/download/${version}/wasm-bindgen-${version}-${triple}.tar.gz";
hash = hashes.${system};
};
sourceRoot = ".";
nativeBuildInputs = pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.autoPatchelfHook ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
find . -maxdepth 2 -type f \( -name 'wasm-bindgen' -o -name 'wasm-bindgen-test-runner' -o -name 'wasm2es6js' \) \
-exec cp {} $out/bin/ \;
chmod +x $out/bin/*
runHook postInstall
'';
};
# Unwrapped LLVM for the secp256k1-sys C -> wasm32 compile (pulled in via
# cashu under the `wasm` feature). cc-rs reads CC_<target>/AR_<target>.
# The wrapped darwin clang injects -isysroot / -mmacosx flags that break
# a freestanding wasm32 target, so point cc-rs at the bare tools.
llvm = pkgs.llvmPackages;
in
{
devShells.default = pkgs.mkShell {
packages = [
rustToolchain
wasm-bindgen-cli
pkgs.wasm-pack
pkgs.binaryen # wasm-opt (optional shrink step)
pkgs.nodejs_22
llvm.clang-unwrapped # clang with the wasm32 backend
llvm.bintools-unwrapped # provides llvm-ar
];
# secp256k1-sys (cc-rs) per-target compiler + archiver.
CC_wasm32_unknown_unknown = "${llvm.clang-unwrapped}/bin/clang";
AR_wasm32_unknown_unknown = "${llvm.bintools-unwrapped}/bin/llvm-ar";
shellHook = ''
echo "pops devShell:"
echo " rustc $(rustc --version 2>/dev/null | cut -d' ' -f2)"
echo " wasm-bindgen $(wasm-bindgen --version 2>/dev/null | cut -d' ' -f2) (Cargo.lock pins 0.2.122)"
echo " wasm-pack $(wasm-pack --version 2>/dev/null | cut -d' ' -f2)"
echo " node $(node --version 2>/dev/null)"
echo "Build the bindings: bash ts/build-wasm.sh"
'';
};
});
}