buildRustPackage: support fixed-point arguments via lib.extendMkDerivation (#382550)
This commit is contained in:
@@ -18,185 +18,185 @@
|
||||
windows,
|
||||
}:
|
||||
|
||||
{
|
||||
name ? "${args.pname}-${args.version}",
|
||||
lib.extendMkDerivation {
|
||||
constructDrv = stdenv.mkDerivation;
|
||||
|
||||
# Name for the vendored dependencies tarball
|
||||
cargoDepsName ? name,
|
||||
|
||||
src ? null,
|
||||
srcs ? null,
|
||||
preUnpack ? null,
|
||||
unpackPhase ? null,
|
||||
postUnpack ? null,
|
||||
cargoPatches ? [ ],
|
||||
patches ? [ ],
|
||||
sourceRoot ? null,
|
||||
cargoRoot ? null,
|
||||
logLevel ? "",
|
||||
buildInputs ? [ ],
|
||||
nativeBuildInputs ? [ ],
|
||||
cargoUpdateHook ? "",
|
||||
cargoDepsHook ? "",
|
||||
buildType ? "release",
|
||||
meta ? { },
|
||||
useFetchCargoVendor ? false,
|
||||
cargoDeps ? null,
|
||||
cargoLock ? null,
|
||||
cargoVendorDir ? null,
|
||||
checkType ? buildType,
|
||||
buildNoDefaultFeatures ? false,
|
||||
checkNoDefaultFeatures ? buildNoDefaultFeatures,
|
||||
buildFeatures ? [ ],
|
||||
checkFeatures ? buildFeatures,
|
||||
useNextest ? false,
|
||||
auditable ? !cargo-auditable.meta.broken,
|
||||
|
||||
depsExtraArgs ? { },
|
||||
|
||||
# Needed to `pushd`/`popd` into a subdir of a tarball if this subdir
|
||||
# contains a Cargo.toml, but isn't part of a workspace (which is e.g. the
|
||||
# case for `rustfmt`/etc from the `rust-sources).
|
||||
# Otherwise, everything from the tarball would've been built/tested.
|
||||
buildAndTestSubdir ? null,
|
||||
...
|
||||
}@args:
|
||||
|
||||
assert
|
||||
cargoVendorDir == null && cargoDeps == null && cargoLock == null
|
||||
->
|
||||
!(args ? cargoSha256 && args.cargoSha256 != null) && !(args ? cargoHash && args.cargoHash != null)
|
||||
-> throw "cargoHash, cargoVendorDir, cargoDeps, or cargoLock must be set";
|
||||
|
||||
let
|
||||
|
||||
cargoDeps' =
|
||||
if cargoVendorDir != null then
|
||||
null
|
||||
else if cargoDeps != null then
|
||||
cargoDeps
|
||||
else if cargoLock != null then
|
||||
importCargoLock cargoLock
|
||||
else if useFetchCargoVendor then
|
||||
fetchCargoVendor (
|
||||
{
|
||||
inherit
|
||||
src
|
||||
srcs
|
||||
sourceRoot
|
||||
cargoRoot
|
||||
preUnpack
|
||||
unpackPhase
|
||||
postUnpack
|
||||
;
|
||||
name = cargoDepsName;
|
||||
patches = cargoPatches;
|
||||
hash = args.cargoHash;
|
||||
}
|
||||
// depsExtraArgs
|
||||
)
|
||||
else
|
||||
fetchCargoTarball (
|
||||
{
|
||||
inherit
|
||||
src
|
||||
srcs
|
||||
sourceRoot
|
||||
cargoRoot
|
||||
preUnpack
|
||||
unpackPhase
|
||||
postUnpack
|
||||
cargoUpdateHook
|
||||
;
|
||||
name = cargoDepsName;
|
||||
patches = cargoPatches;
|
||||
}
|
||||
// lib.optionalAttrs (args ? cargoHash) {
|
||||
hash = args.cargoHash;
|
||||
}
|
||||
// lib.optionalAttrs (args ? cargoSha256) {
|
||||
sha256 = lib.warn "cargoSha256 is deprecated. Please use cargoHash with SRI hash instead" args.cargoSha256;
|
||||
}
|
||||
// depsExtraArgs
|
||||
);
|
||||
|
||||
target = stdenv.hostPlatform.rust.rustcTargetSpec;
|
||||
targetIsJSON = lib.hasSuffix ".json" target;
|
||||
in
|
||||
|
||||
stdenv.mkDerivation (
|
||||
(removeAttrs args [
|
||||
excludeDrvArgNames = [
|
||||
"depsExtraArgs"
|
||||
"cargoUpdateHook"
|
||||
"cargoDeps"
|
||||
"cargoLock"
|
||||
])
|
||||
// lib.optionalAttrs (stdenv.hostPlatform.isDarwin && buildType == "debug") {
|
||||
RUSTFLAGS = "-C split-debuginfo=packed " + (args.RUSTFLAGS or "");
|
||||
}
|
||||
// {
|
||||
cargoDeps = cargoDeps';
|
||||
inherit buildAndTestSubdir;
|
||||
];
|
||||
|
||||
cargoBuildType = buildType;
|
||||
extendDrvArgs =
|
||||
finalAttrs:
|
||||
{
|
||||
name ? "${args.pname}-${args.version}",
|
||||
|
||||
cargoCheckType = checkType;
|
||||
# Name for the vendored dependencies tarball
|
||||
cargoDepsName ? name,
|
||||
|
||||
cargoBuildNoDefaultFeatures = buildNoDefaultFeatures;
|
||||
src ? null,
|
||||
srcs ? null,
|
||||
preUnpack ? null,
|
||||
unpackPhase ? null,
|
||||
postUnpack ? null,
|
||||
cargoPatches ? [ ],
|
||||
patches ? [ ],
|
||||
sourceRoot ? null,
|
||||
cargoRoot ? null,
|
||||
logLevel ? "",
|
||||
buildInputs ? [ ],
|
||||
nativeBuildInputs ? [ ],
|
||||
cargoUpdateHook ? "",
|
||||
cargoDepsHook ? "",
|
||||
buildType ? "release",
|
||||
meta ? { },
|
||||
useFetchCargoVendor ? false,
|
||||
cargoDeps ? null,
|
||||
cargoLock ? null,
|
||||
cargoVendorDir ? null,
|
||||
checkType ? buildType,
|
||||
buildNoDefaultFeatures ? false,
|
||||
checkNoDefaultFeatures ? buildNoDefaultFeatures,
|
||||
buildFeatures ? [ ],
|
||||
checkFeatures ? buildFeatures,
|
||||
useNextest ? false,
|
||||
auditable ? !cargo-auditable.meta.broken,
|
||||
|
||||
cargoCheckNoDefaultFeatures = checkNoDefaultFeatures;
|
||||
depsExtraArgs ? { },
|
||||
|
||||
cargoBuildFeatures = buildFeatures;
|
||||
# Needed to `pushd`/`popd` into a subdir of a tarball if this subdir
|
||||
# contains a Cargo.toml, but isn't part of a workspace (which is e.g. the
|
||||
# case for `rustfmt`/etc from the `rust-sources).
|
||||
# Otherwise, everything from the tarball would've been built/tested.
|
||||
buildAndTestSubdir ? null,
|
||||
...
|
||||
}@args:
|
||||
|
||||
cargoCheckFeatures = checkFeatures;
|
||||
let
|
||||
|
||||
nativeBuildInputs =
|
||||
nativeBuildInputs
|
||||
++ lib.optionals auditable [
|
||||
(buildPackages.cargo-auditable-cargo-wrapper.override {
|
||||
inherit cargo cargo-auditable;
|
||||
})
|
||||
]
|
||||
++ [
|
||||
cargoBuildHook
|
||||
(if useNextest then cargoNextestHook else cargoCheckHook)
|
||||
cargoInstallHook
|
||||
cargoSetupHook
|
||||
rustc
|
||||
cargo
|
||||
];
|
||||
cargoDeps' =
|
||||
if cargoVendorDir != null then
|
||||
null
|
||||
else if cargoDeps != null then
|
||||
cargoDeps
|
||||
else if cargoLock != null then
|
||||
importCargoLock cargoLock
|
||||
else if (args.cargoHash or null == null) && (args.cargoSha256 or null == null) then
|
||||
throw "cargoHash, cargoVendorDir, cargoDeps, or cargoLock must be set"
|
||||
else if useFetchCargoVendor then
|
||||
fetchCargoVendor (
|
||||
{
|
||||
inherit
|
||||
src
|
||||
srcs
|
||||
sourceRoot
|
||||
cargoRoot
|
||||
preUnpack
|
||||
unpackPhase
|
||||
postUnpack
|
||||
;
|
||||
name = cargoDepsName;
|
||||
patches = cargoPatches;
|
||||
hash = args.cargoHash;
|
||||
}
|
||||
// depsExtraArgs
|
||||
)
|
||||
else
|
||||
fetchCargoTarball (
|
||||
{
|
||||
inherit
|
||||
src
|
||||
srcs
|
||||
sourceRoot
|
||||
cargoRoot
|
||||
preUnpack
|
||||
unpackPhase
|
||||
postUnpack
|
||||
cargoUpdateHook
|
||||
;
|
||||
name = cargoDepsName;
|
||||
patches = cargoPatches;
|
||||
}
|
||||
// lib.optionalAttrs (args ? cargoHash) {
|
||||
hash = args.cargoHash;
|
||||
}
|
||||
// lib.optionalAttrs (args ? cargoSha256) {
|
||||
sha256 = lib.warn "cargoSha256 is deprecated. Please use cargoHash with SRI hash instead" args.cargoSha256;
|
||||
}
|
||||
// depsExtraArgs
|
||||
);
|
||||
|
||||
buildInputs =
|
||||
buildInputs
|
||||
++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]
|
||||
++ lib.optionals stdenv.hostPlatform.isMinGW [ windows.pthreads ];
|
||||
target = stdenv.hostPlatform.rust.rustcTargetSpec;
|
||||
targetIsJSON = lib.hasSuffix ".json" target;
|
||||
in
|
||||
lib.optionalAttrs (stdenv.hostPlatform.isDarwin && buildType == "debug") {
|
||||
RUSTFLAGS = "-C split-debuginfo=packed " + (args.RUSTFLAGS or "");
|
||||
}
|
||||
// {
|
||||
cargoDeps = cargoDeps';
|
||||
inherit buildAndTestSubdir;
|
||||
|
||||
patches = cargoPatches ++ patches;
|
||||
cargoBuildType = buildType;
|
||||
|
||||
PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0;
|
||||
cargoCheckType = checkType;
|
||||
|
||||
postUnpack =
|
||||
''
|
||||
eval "$cargoDepsHook"
|
||||
cargoBuildNoDefaultFeatures = buildNoDefaultFeatures;
|
||||
|
||||
export RUST_LOG=${logLevel}
|
||||
''
|
||||
+ (args.postUnpack or "");
|
||||
cargoCheckNoDefaultFeatures = checkNoDefaultFeatures;
|
||||
|
||||
configurePhase =
|
||||
args.configurePhase or ''
|
||||
runHook preConfigure
|
||||
runHook postConfigure
|
||||
'';
|
||||
cargoBuildFeatures = buildFeatures;
|
||||
|
||||
doCheck = args.doCheck or true;
|
||||
cargoCheckFeatures = checkFeatures;
|
||||
|
||||
strictDeps = true;
|
||||
nativeBuildInputs =
|
||||
nativeBuildInputs
|
||||
++ lib.optionals auditable [
|
||||
(buildPackages.cargo-auditable-cargo-wrapper.override {
|
||||
inherit cargo cargo-auditable;
|
||||
})
|
||||
]
|
||||
++ [
|
||||
cargoBuildHook
|
||||
(if useNextest then cargoNextestHook else cargoCheckHook)
|
||||
cargoInstallHook
|
||||
cargoSetupHook
|
||||
rustc
|
||||
cargo
|
||||
];
|
||||
|
||||
meta = meta // {
|
||||
badPlatforms = meta.badPlatforms or [ ] ++ rustc.badTargetPlatforms;
|
||||
# default to Rust's platforms
|
||||
platforms = lib.intersectLists meta.platforms or lib.platforms.all rustc.targetPlatforms;
|
||||
buildInputs =
|
||||
buildInputs
|
||||
++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]
|
||||
++ lib.optionals stdenv.hostPlatform.isMinGW [ windows.pthreads ];
|
||||
|
||||
patches = cargoPatches ++ patches;
|
||||
|
||||
PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0;
|
||||
|
||||
postUnpack =
|
||||
''
|
||||
eval "$cargoDepsHook"
|
||||
|
||||
export RUST_LOG=${logLevel}
|
||||
''
|
||||
+ (args.postUnpack or "");
|
||||
|
||||
configurePhase =
|
||||
args.configurePhase or ''
|
||||
runHook preConfigure
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
||||
doCheck = args.doCheck or true;
|
||||
|
||||
strictDeps = true;
|
||||
|
||||
meta = meta // {
|
||||
badPlatforms = meta.badPlatforms or [ ] ++ rustc.badTargetPlatforms;
|
||||
# default to Rust's platforms
|
||||
platforms = lib.intersectLists meta.platforms or lib.platforms.all rustc.targetPlatforms;
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -30,77 +30,75 @@ let
|
||||
.${uiua_versionType};
|
||||
in
|
||||
|
||||
# buildRustPackage doesn't support finalAttrs, so we can't use finalPackage for the tests
|
||||
lib.fix (
|
||||
uiua:
|
||||
rustPlatform.buildRustPackage rec {
|
||||
pname = "uiua";
|
||||
inherit (versionInfo) version cargoHash;
|
||||
useFetchCargoVendor = true;
|
||||
rustPlatform.buildRustPackage (finalAttrs: {
|
||||
pname = "uiua";
|
||||
inherit (versionInfo) version cargoHash;
|
||||
useFetchCargoVendor = true;
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "uiua-lang";
|
||||
repo = "uiua";
|
||||
inherit (versionInfo) tag hash;
|
||||
};
|
||||
src = fetchFromGitHub {
|
||||
owner = "uiua-lang";
|
||||
repo = "uiua";
|
||||
inherit (versionInfo) tag hash;
|
||||
};
|
||||
|
||||
nativeBuildInputs =
|
||||
lib.optionals (webcamSupport || stdenv.hostPlatform.isDarwin) [ rustPlatform.bindgenHook ]
|
||||
++ lib.optionals audioSupport [ pkg-config ];
|
||||
nativeBuildInputs =
|
||||
lib.optionals (webcamSupport || stdenv.hostPlatform.isDarwin) [ rustPlatform.bindgenHook ]
|
||||
++ lib.optionals audioSupport [ pkg-config ];
|
||||
|
||||
buildInputs =
|
||||
[ libffi ] # we force dynamic linking our own libffi below
|
||||
++ lib.optionals (audioSupport && stdenv.hostPlatform.isLinux) [ alsa-lib ];
|
||||
buildInputs =
|
||||
[ libffi ] # we force dynamic linking our own libffi below
|
||||
++ lib.optionals (audioSupport && stdenv.hostPlatform.isLinux) [ alsa-lib ];
|
||||
|
||||
buildFeatures =
|
||||
[ "libffi/system" ] # force libffi to be linked dynamically instead of rebuilding it
|
||||
++ lib.optional audioSupport "audio"
|
||||
++ lib.optional webcamSupport "webcam"
|
||||
++ lib.optional windowSupport "window";
|
||||
buildFeatures =
|
||||
[ "libffi/system" ] # force libffi to be linked dynamically instead of rebuilding it
|
||||
++ lib.optional audioSupport "audio"
|
||||
++ lib.optional webcamSupport "webcam"
|
||||
++ lib.optional windowSupport "window";
|
||||
|
||||
postFixup =
|
||||
let
|
||||
runtimeDependencies = lib.optionals windowSupport [
|
||||
libGL
|
||||
libxkbcommon
|
||||
wayland
|
||||
xorg.libX11
|
||||
xorg.libXcursor
|
||||
xorg.libXi
|
||||
xorg.libXrandr
|
||||
];
|
||||
in
|
||||
lib.optionalString (runtimeDependencies != [ ] && stdenv.hostPlatform.isLinux) ''
|
||||
patchelf --add-rpath ${lib.makeLibraryPath runtimeDependencies} $out/bin/uiua
|
||||
'';
|
||||
|
||||
nativeInstallCheckInputs = [ versionCheckHook ];
|
||||
versionCheckProgramArg = "--version";
|
||||
doInstallCheck = true;
|
||||
|
||||
passthru.updateScript = versionInfo.updateScript;
|
||||
passthru.tests.run = runCommand "uiua-test-run" { nativeBuildInputs = [ uiua ]; } ''
|
||||
uiua init
|
||||
diff -U3 --color=auto <(uiua run main.ua) <(echo '"Hello, World!"')
|
||||
touch $out
|
||||
postFixup =
|
||||
let
|
||||
runtimeDependencies = lib.optionals windowSupport [
|
||||
libGL
|
||||
libxkbcommon
|
||||
wayland
|
||||
xorg.libX11
|
||||
xorg.libXcursor
|
||||
xorg.libXi
|
||||
xorg.libXrandr
|
||||
];
|
||||
in
|
||||
lib.optionalString (runtimeDependencies != [ ] && stdenv.hostPlatform.isLinux) ''
|
||||
patchelf --add-rpath ${lib.makeLibraryPath runtimeDependencies} $out/bin/uiua
|
||||
'';
|
||||
|
||||
meta = {
|
||||
changelog = "https://github.com/uiua-lang/uiua/blob/${src.rev}/changelog.md";
|
||||
description = "Stack-oriented array programming language with a focus on simplicity, beauty, and tacit code";
|
||||
longDescription = ''
|
||||
Uiua combines the stack-oriented and array-oriented paradigms in a single
|
||||
language. Combining these already terse paradigms results in code with a very
|
||||
high information density and little syntactic noise.
|
||||
nativeInstallCheckInputs = [ versionCheckHook ];
|
||||
versionCheckProgramArg = "--version";
|
||||
doInstallCheck = true;
|
||||
|
||||
passthru.updateScript = versionInfo.updateScript;
|
||||
passthru.tests.run =
|
||||
runCommand "uiua-test-run" { nativeBuildInputs = [ finalAttrs.finalPackage ]; }
|
||||
''
|
||||
uiua init
|
||||
diff -U3 --color=auto <(uiua run main.ua) <(echo '"Hello, World!"')
|
||||
touch $out
|
||||
'';
|
||||
homepage = "https://www.uiua.org/";
|
||||
license = lib.licenses.mit;
|
||||
mainProgram = "uiua";
|
||||
maintainers = with lib.maintainers; [
|
||||
cafkafk
|
||||
tomasajt
|
||||
defelo
|
||||
];
|
||||
};
|
||||
}
|
||||
)
|
||||
|
||||
meta = {
|
||||
changelog = "https://github.com/uiua-lang/uiua/blob/${finalAttrs.src.rev}/changelog.md";
|
||||
description = "Stack-oriented array programming language with a focus on simplicity, beauty, and tacit code";
|
||||
longDescription = ''
|
||||
Uiua combines the stack-oriented and array-oriented paradigms in a single
|
||||
language. Combining these already terse paradigms results in code with a very
|
||||
high information density and little syntactic noise.
|
||||
'';
|
||||
homepage = "https://www.uiua.org/";
|
||||
license = lib.licenses.mit;
|
||||
mainProgram = "uiua";
|
||||
maintainers = with lib.maintainers; [
|
||||
cafkafk
|
||||
tomasajt
|
||||
defelo
|
||||
];
|
||||
};
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user