2018-09-07 13:08:06 +00:00
|
|
|
# Code for buildRustCrate, a Nix function that builds Rust code, just
|
|
|
|
# like Cargo, but using Nix instead.
|
|
|
|
#
|
|
|
|
# This can be useful for deploying packages with NixOps, and to share
|
|
|
|
# binary dependencies between projects.
|
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, defaultCrateOverrides
|
|
|
|
, fetchCrate
|
|
|
|
, pkgsBuildBuild
|
|
|
|
, rustc
|
|
|
|
, cargo
|
|
|
|
, jq
|
2021-09-03 03:38:43 +00:00
|
|
|
, libiconv
|
2021-09-03 03:14:46 +00:00
|
|
|
}:
|
2018-09-07 13:08:06 +00:00
|
|
|
|
|
|
|
let
|
2021-09-03 03:14:46 +00:00
|
|
|
# Create rustc arguments to link against the given list of dependencies
|
|
|
|
# and renames.
|
|
|
|
#
|
|
|
|
# See docs for crateRenames below.
|
|
|
|
mkRustcDepArgs = dependencies: crateRenames:
|
|
|
|
lib.concatMapStringsSep " "
|
|
|
|
(dep:
|
2019-09-08 06:18:09 +00:00
|
|
|
let
|
2021-09-03 03:14:46 +00:00
|
|
|
normalizeName = lib.replaceStrings [ "-" ] [ "_" ];
|
2020-04-09 22:55:44 +00:00
|
|
|
extern = normalizeName dep.libName;
|
|
|
|
# Find a choice that matches in name and optionally version.
|
|
|
|
findMatchOrUseExtern = choices:
|
2021-09-03 03:14:46 +00:00
|
|
|
lib.findFirst
|
|
|
|
(choice:
|
|
|
|
(!(choice ? version)
|
|
|
|
|| choice.version == dep.version or ""))
|
|
|
|
{ rename = extern; }
|
|
|
|
choices;
|
|
|
|
name =
|
|
|
|
if lib.hasAttr dep.crateName crateRenames then
|
|
|
|
let choices = crateRenames.${dep.crateName};
|
|
|
|
in
|
|
|
|
normalizeName (
|
|
|
|
if builtins.isList choices
|
|
|
|
then (findMatchOrUseExtern choices).rename
|
|
|
|
else choices
|
|
|
|
)
|
|
|
|
else
|
|
|
|
extern;
|
2022-01-12 08:48:49 +00:00
|
|
|
opts = lib.optionalString (dep.stdlib or false) "noprelude:";
|
|
|
|
filename =
|
|
|
|
if lib.any (x: x == "lib" || x == "rlib") dep.crateType
|
|
|
|
then "${dep.metadata}.rlib"
|
2024-06-06 13:30:55 +00:00
|
|
|
# Adjust lib filename for crates of type proc-macro. Proc macros are compiled/run on the build platform architecture.
|
|
|
|
else if (lib.attrByPath [ "procMacro" ] false dep) then "${dep.metadata}${stdenv.buildPlatform.extensions.library}"
|
2024-06-10 13:19:53 +00:00
|
|
|
else "${dep.metadata}${stdenv.hostPlatform.extensions.library}";
|
2021-09-03 03:14:46 +00:00
|
|
|
in
|
2022-01-12 08:48:49 +00:00
|
|
|
" --extern ${opts}${name}=${dep.lib}/lib/lib${extern}-${filename}"
|
2021-09-03 03:14:46 +00:00
|
|
|
)
|
|
|
|
dependencies;
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
# Create feature arguments for rustc.
|
|
|
|
mkRustcFeatureArgs = lib.concatMapStringsSep " " (f: ''--cfg feature=\"${f}\"'');
|
2020-06-12 15:09:45 +00:00
|
|
|
|
2022-01-12 08:48:49 +00:00
|
|
|
# Whether we need to use unstable command line flags
|
|
|
|
#
|
|
|
|
# Currently just needed for standard library dependencies, which have a
|
|
|
|
# special "noprelude:" modifier. If in later versions of Rust this is
|
|
|
|
# stabilized we can account for that here, too, so we don't opt into
|
|
|
|
# instability unnecessarily.
|
|
|
|
needUnstableCLI = dependencies:
|
|
|
|
lib.any (dep: dep.stdlib or false) dependencies;
|
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
inherit (import ./log.nix { inherit lib; }) noisily echo_colored;
|
2019-12-11 21:27:12 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
configureCrate = import ./configure-crate.nix {
|
lib.systems: elaborate Rust metadata
We need this stuff to be available in lib so make-derivation.nix can
access it to construct the Meson cross file.
This has a couple of other advantages:
- It makes Rust less special. Now figuring out what Rust calls a
platform is the same as figuring out what Linux or QEMU call it.
- We can unify the schema used to define Rust targets, and the schema
used to access those values later. Just like you can set "config"
or "system" in a platform definition, and then access those same
keys on the elaborated platform, you can now set "rustcTarget" in
your crossSystem, and then access "stdenv.hostPlatform.rustcTarget"
in your code.
"rustcTarget", "rustcTargetSpec", "cargoShortTarget", and
"cargoEnvVarTarget" have the "rustc" and "cargo" prefixes because
these are not exposed to code by the compiler, and are not
standardized. The arch/os/etc. variables are all named to match the
forms in the Rust target spec JSON.
The new rust.target-family only takes a list, since we don't need to
worry about backwards compatibility when that name is used.
The old APIs are all still functional with no warning for now, so that
it's possible for external code to use a single API on both 23.05 and
23.11. We can introduce the warnings once 23.05 is EOL, and make them
hard errors when 23.11 is EOL.
2023-05-09 13:38:32 +00:00
|
|
|
inherit lib stdenv echo_colored noisily mkRustcDepArgs mkRustcFeatureArgs;
|
2021-09-03 03:14:46 +00:00
|
|
|
};
|
2019-12-11 21:27:12 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
installCrate = import ./install-crate.nix { inherit stdenv; };
|
2019-12-11 20:53:42 +00:00
|
|
|
in
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
/* The overridable pkgs.buildRustCrate function.
|
|
|
|
*
|
|
|
|
* Any unrecognized parameters will be passed as to
|
|
|
|
* the underlying stdenv.mkDerivation.
|
|
|
|
*/
|
|
|
|
crate_: lib.makeOverridable
|
|
|
|
(
|
|
|
|
# The rust compiler to use.
|
|
|
|
#
|
|
|
|
# Default: pkgs.rustc
|
2024-09-03 17:26:24 +00:00
|
|
|
{ rust ? rustc
|
|
|
|
# The cargo package to use for getting some metadata.
|
|
|
|
#
|
|
|
|
# Default: pkgs.cargo
|
|
|
|
, cargo ? cargo
|
2021-09-03 03:14:46 +00:00
|
|
|
# Whether to build a release version (`true`) or a debug
|
|
|
|
# version (`false`). Debug versions are faster to build
|
|
|
|
# but might be much slower at runtime.
|
|
|
|
, release
|
|
|
|
# Whether to print rustc invocations etc.
|
|
|
|
#
|
|
|
|
# Example: false
|
|
|
|
# Default: true
|
|
|
|
, verbose
|
|
|
|
# A list of rust/cargo features to enable while building the crate.
|
|
|
|
# Example: [ "std" "async" ]
|
|
|
|
, features
|
|
|
|
# Additional native build inputs for building this crate.
|
|
|
|
, nativeBuildInputs
|
|
|
|
# Additional build inputs for building this crate.
|
|
|
|
#
|
|
|
|
# Example: [ pkgs.openssl ]
|
|
|
|
, buildInputs
|
|
|
|
# Allows to override the parameters to buildRustCrate
|
|
|
|
# for any rust dependency in the transitive build tree.
|
|
|
|
#
|
|
|
|
# Default: pkgs.defaultCrateOverrides
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# pkgs.defaultCrateOverrides // {
|
|
|
|
# hello = attrs: { buildInputs = [ openssl ]; };
|
|
|
|
# }
|
|
|
|
, crateOverrides
|
2023-06-09 13:30:00 +00:00
|
|
|
# Rust library dependencies, i.e. other libraries that were built
|
2021-09-03 03:14:46 +00:00
|
|
|
# with buildRustCrate.
|
|
|
|
, dependencies
|
2023-06-09 13:30:00 +00:00
|
|
|
# Rust build dependencies, i.e. other libraries that were built
|
2021-09-03 03:14:46 +00:00
|
|
|
# with buildRustCrate and are used by a build script.
|
|
|
|
, buildDependencies
|
|
|
|
# Specify the "extern" name of a library if it differs from the library target.
|
|
|
|
# See above for an extended explanation.
|
|
|
|
#
|
|
|
|
# Default: no renames.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# `crateRenames` supports two formats.
|
|
|
|
#
|
|
|
|
# The simple version is an attrset that maps the
|
|
|
|
# `crateName`s of the dependencies to their alternative
|
|
|
|
# names.
|
|
|
|
#
|
|
|
|
# ```nix
|
|
|
|
# {
|
|
|
|
# my_crate_name = "my_alternative_name";
|
|
|
|
# # ...
|
|
|
|
# }
|
|
|
|
# ```
|
|
|
|
#
|
|
|
|
# The extended version is also keyed by the `crateName`s but allows
|
|
|
|
# different names for different crate versions:
|
|
|
|
#
|
|
|
|
# ```nix
|
|
|
|
# {
|
|
|
|
# my_crate_name = [
|
|
|
|
# { version = "1.2.3"; rename = "my_alternative_name01"; }
|
|
|
|
# { version = "3.2.3"; rename = "my_alternative_name03"; }
|
|
|
|
# ]
|
|
|
|
# # ...
|
|
|
|
# }
|
|
|
|
# ```
|
|
|
|
#
|
|
|
|
# This roughly corresponds to the following snippet in Cargo.toml:
|
|
|
|
#
|
|
|
|
# ```toml
|
|
|
|
# [dependencies]
|
|
|
|
# my_alternative_name01 = { package = "my_crate_name", version = "0.1" }
|
|
|
|
# my_alternative_name03 = { package = "my_crate_name", version = "0.3" }
|
|
|
|
# ```
|
|
|
|
#
|
|
|
|
# Dependencies which use the lib target name as extern name, do not need
|
|
|
|
# to be specified in the crateRenames, even if their crate name differs.
|
|
|
|
#
|
|
|
|
# Including multiple versions of a crate is very popular during
|
|
|
|
# ecosystem transitions, e.g. from futures 0.1 to futures 0.3.
|
|
|
|
, crateRenames
|
|
|
|
# A list of extra options to pass to rustc.
|
|
|
|
#
|
|
|
|
# Example: [ "-Z debuginfo=2" ]
|
|
|
|
# Default: []
|
|
|
|
, extraRustcOpts
|
2021-06-30 15:50:45 +00:00
|
|
|
# A list of extra options to pass to rustc when building a build.rs.
|
|
|
|
#
|
|
|
|
# Example: [ "-Z debuginfo=2" ]
|
|
|
|
# Default: []
|
|
|
|
, extraRustcOptsForBuildRs
|
2021-09-03 03:14:46 +00:00
|
|
|
# Whether to enable building tests.
|
|
|
|
# Use true to enable.
|
|
|
|
# Default: false
|
|
|
|
, buildTests
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, preUnpack
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, postUnpack
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, prePatch
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, patches
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, postPatch
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, preConfigure
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, postConfigure
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, preBuild
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, postBuild
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, preInstall
|
|
|
|
# Passed to stdenv.mkDerivation.
|
|
|
|
, postInstall
|
|
|
|
}:
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
let
|
|
|
|
crate = crate_ // (lib.attrByPath [ crate_.crateName ] (attr: { }) crateOverrides crate_);
|
|
|
|
dependencies_ = dependencies;
|
|
|
|
buildDependencies_ = buildDependencies;
|
|
|
|
processedAttrs = [
|
|
|
|
"src"
|
|
|
|
"nativeBuildInputs"
|
|
|
|
"buildInputs"
|
|
|
|
"crateBin"
|
|
|
|
"crateLib"
|
|
|
|
"libName"
|
|
|
|
"libPath"
|
|
|
|
"buildDependencies"
|
|
|
|
"dependencies"
|
|
|
|
"features"
|
|
|
|
"crateRenames"
|
|
|
|
"crateName"
|
|
|
|
"version"
|
|
|
|
"build"
|
|
|
|
"authors"
|
|
|
|
"colors"
|
|
|
|
"edition"
|
|
|
|
"buildTests"
|
2021-10-12 00:25:08 +00:00
|
|
|
"codegenUnits"
|
2023-11-11 06:15:23 +00:00
|
|
|
"links"
|
2021-09-03 03:14:46 +00:00
|
|
|
];
|
|
|
|
extraDerivationAttrs = builtins.removeAttrs crate processedAttrs;
|
|
|
|
nativeBuildInputs_ = nativeBuildInputs;
|
|
|
|
buildInputs_ = buildInputs;
|
|
|
|
extraRustcOpts_ = extraRustcOpts;
|
2021-06-30 15:50:45 +00:00
|
|
|
extraRustcOptsForBuildRs_ = extraRustcOptsForBuildRs;
|
2021-09-03 03:14:46 +00:00
|
|
|
buildTests_ = buildTests;
|
2019-12-11 23:06:22 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
# crate2nix has a hack for the old bash based build script that did split
|
|
|
|
# entries at `,`. No we have to work around that hack.
|
|
|
|
# https://github.com/kolloch/crate2nix/blame/5b19c1b14e1b0e5522c3e44e300d0b332dc939e7/crate2nix/templates/build.nix.tera#L89
|
|
|
|
crateBin = lib.filter (bin: !(bin ? name && bin.name == ",")) (crate.crateBin or [ ]);
|
|
|
|
hasCrateBin = crate ? crateBin;
|
2024-09-03 17:26:24 +00:00
|
|
|
|
|
|
|
buildCrate = import ./build-crate.nix {
|
|
|
|
inherit lib stdenv mkRustcDepArgs mkRustcFeatureArgs needUnstableCLI;
|
|
|
|
rustc = rust;
|
|
|
|
};
|
2021-09-03 03:14:46 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (rec {
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
inherit (crate) crateName;
|
|
|
|
inherit
|
|
|
|
preUnpack
|
|
|
|
postUnpack
|
|
|
|
prePatch
|
|
|
|
patches
|
|
|
|
postPatch
|
|
|
|
preConfigure
|
|
|
|
postConfigure
|
|
|
|
preBuild
|
|
|
|
postBuild
|
|
|
|
preInstall
|
|
|
|
postInstall
|
|
|
|
buildTests
|
|
|
|
;
|
2019-12-17 23:51:26 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
src = crate.src or (fetchCrate { inherit (crate) crateName version sha256; });
|
|
|
|
name = "rust_${crate.crateName}-${crate.version}${lib.optionalString buildTests_ "-test"}";
|
|
|
|
version = crate.version;
|
|
|
|
depsBuildBuild = [ pkgsBuildBuild.stdenv.cc ];
|
2024-09-03 17:26:24 +00:00
|
|
|
nativeBuildInputs = [ rust cargo jq ]
|
2024-06-14 22:28:21 +00:00
|
|
|
++ lib.optionals stdenv.hasCC [ stdenv.cc ]
|
2023-03-08 17:48:13 +00:00
|
|
|
++ lib.optionals stdenv.buildPlatform.isDarwin [ libiconv ]
|
|
|
|
++ (crate.nativeBuildInputs or [ ]) ++ nativeBuildInputs_;
|
2021-09-03 03:38:43 +00:00
|
|
|
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ] ++ (crate.buildInputs or [ ]) ++ buildInputs_;
|
2021-09-03 03:14:46 +00:00
|
|
|
dependencies = map lib.getLib dependencies_;
|
|
|
|
buildDependencies = map lib.getLib buildDependencies_;
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
completeDeps = lib.unique (dependencies ++ lib.concatMap (dep: dep.completeDeps) dependencies);
|
|
|
|
completeBuildDeps = lib.unique (
|
|
|
|
buildDependencies
|
|
|
|
++ lib.concatMap (dep: dep.completeBuildDeps ++ dep.completeDeps) buildDependencies
|
|
|
|
);
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
# Create a list of features that are enabled by the crate itself and
|
|
|
|
# through the features argument of buildRustCrate. Exclude features
|
2022-04-16 00:13:47 +00:00
|
|
|
# with a forward slash, since they are passed through to dependencies,
|
|
|
|
# and dep: features, since they're internal-only and do nothing except
|
|
|
|
# enable optional dependencies.
|
2021-09-03 03:14:46 +00:00
|
|
|
crateFeatures = lib.optionals (crate ? features)
|
2022-04-16 00:13:47 +00:00
|
|
|
(builtins.filter
|
|
|
|
(f: !(lib.hasInfix "/" f || lib.hasPrefix "dep:" f))
|
|
|
|
(crate.features ++ features)
|
|
|
|
);
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2023-06-18 09:27:44 +00:00
|
|
|
libName = if crate ? libName then crate.libName else crate.crateName;
|
2023-02-06 20:49:02 +00:00
|
|
|
libPath = lib.optionalString (crate ? libPath) crate.libPath;
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
# Seed the symbol hashes with something unique every time.
|
|
|
|
# https://doc.rust-lang.org/1.0.0/rustc/metadata/loader/index.html#frobbing-symbols
|
|
|
|
metadata =
|
|
|
|
let
|
|
|
|
depsMetadata = lib.foldl' (str: dep: str + dep.metadata) "" (dependencies ++ buildDependencies);
|
|
|
|
hashedMetadata = builtins.hashString "sha256"
|
|
|
|
(crateName + "-" + crateVersion + "___" + toString (mkRustcFeatureArgs crateFeatures) +
|
lib.systems: elaborate Rust metadata
We need this stuff to be available in lib so make-derivation.nix can
access it to construct the Meson cross file.
This has a couple of other advantages:
- It makes Rust less special. Now figuring out what Rust calls a
platform is the same as figuring out what Linux or QEMU call it.
- We can unify the schema used to define Rust targets, and the schema
used to access those values later. Just like you can set "config"
or "system" in a platform definition, and then access those same
keys on the elaborated platform, you can now set "rustcTarget" in
your crossSystem, and then access "stdenv.hostPlatform.rustcTarget"
in your code.
"rustcTarget", "rustcTargetSpec", "cargoShortTarget", and
"cargoEnvVarTarget" have the "rustc" and "cargo" prefixes because
these are not exposed to code by the compiler, and are not
standardized. The arch/os/etc. variables are all named to match the
forms in the Rust target spec JSON.
The new rust.target-family only takes a list, since we don't need to
worry about backwards compatibility when that name is used.
The old APIs are all still functional with no warning for now, so that
it's possible for external code to use a single API on both 23.05 and
23.11. We can introduce the warnings once 23.05 is EOL, and make them
hard errors when 23.11 is EOL.
2023-05-09 13:38:32 +00:00
|
|
|
"___" + depsMetadata + "___" + stdenv.hostPlatform.rust.rustcTarget);
|
2021-09-03 03:14:46 +00:00
|
|
|
in
|
|
|
|
lib.substring 0 10 hashedMetadata;
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
build = crate.build or "";
|
|
|
|
# Either set to a concrete sub path to the crate root
|
|
|
|
# or use `null` for auto-detect.
|
|
|
|
workspace_member = crate.workspace_member or ".";
|
|
|
|
crateAuthors = if crate ? authors && lib.isList crate.authors then crate.authors else [ ];
|
2023-12-15 11:28:40 +00:00
|
|
|
crateDescription = crate.description or "";
|
2021-09-03 03:14:46 +00:00
|
|
|
crateHomepage = crate.homepage or "";
|
2023-12-15 11:28:40 +00:00
|
|
|
crateLicense = crate.license or "";
|
|
|
|
crateLicenseFile = crate.license-file or "";
|
2023-11-11 06:15:23 +00:00
|
|
|
crateLinks = crate.links or "";
|
2023-12-15 11:28:40 +00:00
|
|
|
crateReadme = crate.readme or "";
|
|
|
|
crateRepository = crate.repository or "";
|
|
|
|
crateRustVersion = crate.rust-version or "";
|
|
|
|
crateVersion = crate.version;
|
2021-09-03 03:14:46 +00:00
|
|
|
crateType =
|
|
|
|
if lib.attrByPath [ "procMacro" ] false crate then [ "proc-macro" ] else
|
|
|
|
if lib.attrByPath [ "plugin" ] false crate then [ "dylib" ] else
|
|
|
|
(crate.type or [ "lib" ]);
|
|
|
|
colors = lib.attrByPath [ "colors" ] "always" crate;
|
|
|
|
extraLinkFlags = lib.concatStringsSep " " (crate.extraLinkFlags or [ ]);
|
|
|
|
edition = crate.edition or null;
|
2023-06-18 09:27:44 +00:00
|
|
|
codegenUnits = if crate ? codegenUnits then crate.codegenUnits else 1;
|
2021-09-03 03:14:46 +00:00
|
|
|
extraRustcOpts =
|
|
|
|
lib.optionals (crate ? extraRustcOpts) crate.extraRustcOpts
|
|
|
|
++ extraRustcOpts_
|
|
|
|
++ (lib.optional (edition != null) "--edition ${edition}");
|
2021-06-30 15:50:45 +00:00
|
|
|
extraRustcOptsForBuildRs =
|
|
|
|
lib.optionals (crate ? extraRustcOptsForBuildRs) crate.extraRustcOptsForBuildRs
|
|
|
|
++ extraRustcOptsForBuildRs_
|
|
|
|
++ (lib.optional (edition != null) "--edition ${edition}");
|
2019-02-18 00:09:54 +00:00
|
|
|
|
2019-12-17 20:15:53 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
configurePhase = configureCrate {
|
2024-06-28 08:20:41 +00:00
|
|
|
inherit crateName crateType buildDependencies completeDeps completeBuildDeps crateDescription
|
2023-11-11 06:15:23 +00:00
|
|
|
crateFeatures crateRenames libName build workspace_member release libPath crateVersion crateLinks
|
2021-06-30 15:50:45 +00:00
|
|
|
extraLinkFlags extraRustcOptsForBuildRs
|
2023-12-15 11:28:40 +00:00
|
|
|
crateLicense crateLicenseFile crateReadme crateRepository crateRustVersion
|
2021-10-12 00:25:08 +00:00
|
|
|
crateAuthors crateHomepage verbose colors codegenUnits;
|
2021-09-03 03:14:46 +00:00
|
|
|
};
|
|
|
|
buildPhase = buildCrate {
|
|
|
|
inherit crateName dependencies
|
|
|
|
crateFeatures crateRenames libName release libPath crateType
|
|
|
|
metadata hasCrateBin crateBin verbose colors
|
2021-10-12 00:25:08 +00:00
|
|
|
extraRustcOpts buildTests codegenUnits;
|
2021-09-03 03:14:46 +00:00
|
|
|
};
|
2023-01-15 08:11:55 +00:00
|
|
|
dontStrip = !release;
|
2023-09-18 11:29:22 +00:00
|
|
|
|
2023-09-23 08:19:03 +00:00
|
|
|
# We need to preserve metadata in .rlib, which might get stripped on macOS. See https://github.com/NixOS/nixpkgs/issues/218712
|
2023-09-18 11:29:22 +00:00
|
|
|
stripExclude = [ "*.rlib" ];
|
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
installPhase = installCrate crateName metadata buildTests;
|
2018-09-07 13:08:06 +00:00
|
|
|
|
2021-09-03 03:14:46 +00:00
|
|
|
# depending on the test setting we are either producing something with bins
|
|
|
|
# and libs or just test binaries
|
|
|
|
outputs = if buildTests then [ "out" ] else [ "out" "lib" ];
|
|
|
|
outputDev = if buildTests then [ "out" ] else [ "lib" ];
|
2019-11-20 06:30:06 +00:00
|
|
|
|
2022-05-05 14:25:27 +00:00
|
|
|
meta = {
|
|
|
|
mainProgram = crateName;
|
2023-07-25 04:41:22 +00:00
|
|
|
badPlatforms = [
|
|
|
|
# Rust is currently unable to target the n32 ABI
|
|
|
|
lib.systems.inspect.patterns.isMips64n32
|
|
|
|
];
|
2022-05-05 14:25:27 +00:00
|
|
|
};
|
2021-09-03 03:14:46 +00:00
|
|
|
} // extraDerivationAttrs
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
2024-09-03 17:26:24 +00:00
|
|
|
rust = crate_.rust or rustc;
|
|
|
|
cargo = crate_.cargo or cargo;
|
2018-09-07 13:08:06 +00:00
|
|
|
release = crate_.release or true;
|
|
|
|
verbose = crate_.verbose or true;
|
2021-09-03 03:14:46 +00:00
|
|
|
extraRustcOpts = [ ];
|
2021-06-30 15:50:45 +00:00
|
|
|
extraRustcOptsForBuildRs = [ ];
|
2021-09-03 03:14:46 +00:00
|
|
|
features = [ ];
|
|
|
|
nativeBuildInputs = [ ];
|
|
|
|
buildInputs = [ ];
|
2018-09-07 13:08:06 +00:00
|
|
|
crateOverrides = defaultCrateOverrides;
|
|
|
|
preUnpack = crate_.preUnpack or "";
|
|
|
|
postUnpack = crate_.postUnpack or "";
|
|
|
|
prePatch = crate_.prePatch or "";
|
2021-09-03 03:14:46 +00:00
|
|
|
patches = crate_.patches or [ ];
|
2018-09-07 13:08:06 +00:00
|
|
|
postPatch = crate_.postPatch or "";
|
|
|
|
preConfigure = crate_.preConfigure or "";
|
|
|
|
postConfigure = crate_.postConfigure or "";
|
|
|
|
preBuild = crate_.preBuild or "";
|
|
|
|
postBuild = crate_.postBuild or "";
|
|
|
|
preInstall = crate_.preInstall or "";
|
|
|
|
postInstall = crate_.postInstall or "";
|
2021-09-03 03:14:46 +00:00
|
|
|
dependencies = crate_.dependencies or [ ];
|
|
|
|
buildDependencies = crate_.buildDependencies or [ ];
|
|
|
|
crateRenames = crate_.crateRenames or { };
|
2019-12-17 20:15:53 +00:00
|
|
|
buildTests = crate_.buildTests or false;
|
2018-09-07 13:08:06 +00:00
|
|
|
}
|