-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
188 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
rustPlatform, | ||
jq, | ||
rsync, | ||
stdenv, | ||
fenix, | ||
}: | ||
{ | ||
buildRustPackage = | ||
{ | ||
target, | ||
src, | ||
cargoLock ? { | ||
lockFile = "${src}/Cargo.lock"; | ||
}, | ||
release ? true, | ||
... | ||
}@args: | ||
let | ||
# Setup a toolchain for the the host system targeting `target`. | ||
toolchain = | ||
let | ||
inherit (fenix) stable targets combine; | ||
in | ||
combine [ | ||
stable.rustc | ||
stable.cargo | ||
targets.${target}.stable.rust-std | ||
]; | ||
|
||
# Create `vendor` folder with all dependencies. | ||
vendoredDependencies = rustPlatform.importCargoLock cargoLock; | ||
|
||
rustcTargetDir = "target/${target}/${if release then "release" else "debug"}"; | ||
in | ||
stdenv.mkDerivation ( | ||
(removeAttrs args [ "cargoLock" ]) | ||
// { | ||
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ | ||
toolchain | ||
jq | ||
rsync | ||
]; | ||
dontConfigure = true; | ||
buildPhase = '' | ||
runHook preBuild | ||
cargo build \ | ||
--config 'source.crates-io.replace-with="vendored-sources"' \ | ||
--config 'source.vendored-sources.directory="${vendoredDependencies}"' \ | ||
--offline \ | ||
--target ${target} ${if release then "-r" else ""} | ||
runHook postBuild | ||
''; | ||
installPhase = '' | ||
runHook preInstall; | ||
mkdir -p $out | ||
find ${rustcTargetDir} -type f -maxdepth 1 | \ | ||
xargs -I ___X -n1 cp ___X $out | ||
runHook postInstall; | ||
''; | ||
} | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
fenix, | ||
wasm-bindgen, | ||
rust-helpers, | ||
stdenv, | ||
}: | ||
{ | ||
buildSquooshCodecRust = | ||
{ | ||
name, | ||
src, | ||
cargoLock ? { | ||
lockFile = "${src}/Cargo.lock"; | ||
}, | ||
wasmBindgen ? { | ||
sha256 = ""; | ||
}, | ||
... | ||
}@args: | ||
let | ||
codecBuild = rust-helpers.lib.buildRustPackage { | ||
inherit src cargoLock; | ||
name = "${name}-codec"; | ||
target = "wasm32-unknown-unknown"; | ||
}; | ||
|
||
wasm-bindgen-bin = wasm-bindgen.lib.buildFromCargoLock { | ||
inherit cargoLock; | ||
sha256 = wasmBindgen.sha256; | ||
}; | ||
in | ||
if wasmBindgen != null then | ||
stdenv.mkDerivation ( | ||
(removeAttrs args [ "cargoLock" ]) | ||
// { | ||
inherit codecBuild; | ||
dontConfigure = true; | ||
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ wasm-bindgen-bin ]; | ||
buildPhase = '' | ||
runHook preBuild | ||
wasm-bindgen --target web --out-dir $out $codecBuild/*.wasm | ||
runHook postBuild | ||
''; | ||
dontInstall = true; | ||
} | ||
) | ||
else | ||
codecBuild; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
lib, | ||
fetchCrate, | ||
rustPlatform, | ||
curl, | ||
darwin, | ||
}: | ||
rec { | ||
build = | ||
{ version, sha256 }: | ||
let | ||
src = fetchCrate { | ||
pname = "wasm-bindgen-cli"; | ||
inherit version sha256; | ||
}; | ||
|
||
cargoLock = { | ||
lockFile = "${src}/Cargo.lock"; | ||
}; | ||
in | ||
rustPlatform.buildRustPackage { | ||
name = "wasm-bindgen-cli"; | ||
inherit src cargoLock; | ||
buildInputs = [ | ||
curl | ||
darwin.apple_sdk.frameworks.Security | ||
]; | ||
doCheck = false; | ||
}; | ||
|
||
buildFromCargoLock = | ||
{ | ||
system, | ||
cargoLock, | ||
sha256, | ||
}: | ||
assert (cargoLock.lockFile or null == null) != (cargoLock.lockFileContents or null == null); | ||
let | ||
lockFileContents = | ||
if cargoLock.lockFile != null then | ||
builtins.readFile cargoLock.lockFile | ||
else | ||
cargoLock.lockFileContents; | ||
|
||
parsedLockFile = builtins.fromTOML lockFileContents; | ||
|
||
wasm-bindgen-version = | ||
(lib.lists.findFirst (x: x.name == "wasm-bindgen") null parsedLockFile.package).version; | ||
in | ||
assert wasm-bindgen-version != null; | ||
build { | ||
inherit system sha256; | ||
version = wasm-bindgen-version; | ||
}; | ||
} |
Oops, something went wrong.