-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reintroducing mkRustCrate #31150
Reintroducing mkRustCrate #31150
Changes from 3 commits
a20704c
7979239
2d85124
00e93d5
4b5aa82
08046ce
6088db3
235a48e
6846126
1917e32
655f44a
cf4ec94
a694f61
d0a68ff
ca81cad
b4c5585
4ce91ee
1f338c1
4121d59
428f66a
01645cf
2d2490a
0387786
6ffd5b4
7b212b8
f7bed04
95ed173
099e713
68b7867
50b984f
993d376
a99ef12
7e6e3b5
c82be14
ea0cf4b
4c788cc
240fc52
0e8ef4b
5555123
457f9f5
c21a241
59d16ef
7d7fe21
fc84be3
1cd1fca
cd0f359
bf70097
f84ad34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,270 @@ | ||
# Copyright 2017 Pierre-Étienne Meunier | ||
# | ||
# This file is licensed under the Apache-2.0 license, and under the | ||
# MIT license, at your convenience. | ||
|
||
{ lib, buildPlatform, stdenv }: | ||
|
||
let buildCrate = { crateName, crateVersion, dependencies, complete, crateFeatures, libName, build, release, libPath, crateType, metadata, crateBin, finalBins, verboseBuild }: | ||
|
||
let depsDir = builtins.foldl' (deps: dep: deps + " " + dep.out) "" dependencies; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
completeDepsDir = builtins.foldl' (deps: dep: deps + " " + dep.out) "" complete; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above. |
||
deps = | ||
builtins.foldl' (deps: dep: | ||
let extern = lib.strings.replaceStrings ["-"] ["_"] dep.libName; in | ||
deps + (if dep.crateType == "lib" then | ||
" --extern ${extern}=${dep.out}/lib${extern}-${dep.metadata}.rlib" | ||
else | ||
" --extern ${extern}=${dep.out}/lib${extern}-${dep.metadata}.so") | ||
) "" dependencies; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
optLevel = if release then 3 else 0; | ||
rustcOpts = (if release then "-C opt-level=3" else "-C debuginfo=2"); | ||
rustcMeta = "-C metadata=" + metadata + " -C extra-filename=-" + metadata; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rustcMeta = "-C metadata=${metadata} -C extra-filename=-${metadata}"; |
||
in '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
norm="$(printf '\033[0m')" #returns to "normal" | ||
bold="$(printf '\033[0;1m')" #set bold | ||
green="$(printf '\033[0;32m')" #set red | ||
boldgreen="$(printf '\033[0;1;32m')" #set bold, and set red. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to do this, but I keep getting the error
When I set a TERM to my terminal, I get instead:
The command I'm trying to use is
|
||
|
||
mkdir -p target/deps | ||
mkdir -p target/build | ||
chmod uga+w target -R | ||
for i in ${completeDepsDir}; do | ||
ln -s -f $i/*.rlib target/deps #*/ | ||
ln -s -f $i/*.so target/deps #*/ | ||
if [ -e "$i/link" ]; then | ||
cat $i/link >> target/link | ||
cat $i/link >> target/link.final | ||
fi | ||
if [ -e $i/env ]; then | ||
source $i/env | ||
fi | ||
done | ||
if [ -e target/link ]; then | ||
sort -u target/link > target/link.sorted | ||
mv target/link.sorted target/link | ||
sort -u target/link.final > target/link.final.sorted | ||
mv target/link.final.sorted target/link.final | ||
tr '\n' ' ' < target/link > target/link_ | ||
fi | ||
EXTRA_BUILD="" | ||
BUILD_OUT_DIR="" | ||
export CARGO_PKG_NAME=${crateName} | ||
export CARGO_PKG_VERSION=${crateVersion} | ||
export CARGO_CFG_TARGET_ARCH=$(echo ${buildPlatform.system} | sed -e "s/\([^-]*\)-\([^-]*\)/\1/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. buildPlatform.parsed.cpu.name |
||
export CARGO_CFG_TARGET_OS=$(echo ${buildPlatform.system} | sed -e "s/\([^-]*\)-\([^-]*\)/\2/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. buildPlatform.parsed.kernel.name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the documentation for this? If it doesn't exist, I'd like to add it somewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found out, while playing the $ nix-repl
Welcome to Nix version 1.11.15. Type :? for help.
nix-repl> :l <nixpkgs>
Added 7885 variables.
nix-repl> buildPlatform.parsed
{ _type = "system"; abi = { ... }; cpu = { ... }; kernel = { ... }; vendor = { ... }; }
nix-repl>buildPlatform.parsed.kernel
{ _type = "kernel"; execFormat = { ... }; families = { ... }; name = "linux"; } I think this was merged recently for cross compiling. It comes from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might belong to the nixpkgs documentation then, located in |
||
|
||
export CARGO_CFG_TARGET_ENV="gnu" | ||
export CARGO_MANIFEST_DIR="." | ||
export DEBUG="${toString (!release)}" | ||
export OPT_LEVEL="${toString optLevel}" | ||
export TARGET="${buildPlatform.system}-gnu" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
export HOST="${buildPlatform.system}-gnu" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
export PROFILE=${if release then "release" else "debug"} | ||
export OUT_DIR=$(pwd)/target/build/${crateName}.out | ||
|
||
BUILD="" | ||
if [[ ! -z "${build}" ]] ; then | ||
BUILD=${build} | ||
elif [[ -e "build.rs" ]]; then | ||
BUILD="build.rs" | ||
fi | ||
if [[ ! -z "$BUILD" ]] ; then | ||
echo "$boldgreen" "Building $BUILD (${libName})" "$norm" | ||
mkdir -p target/build/${crateName} | ||
if [ -e target/link_ ]; then | ||
rustc --crate-name build_script_build $BUILD --crate-type bin ${rustcOpts} ${crateFeatures} --out-dir target/build/${crateName} --emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow $(cat target/link_) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you wrap long lines like this for readability? |
||
else | ||
rustc --crate-name build_script_build $BUILD --crate-type bin ${rustcOpts} ${crateFeatures} --out-dir target/build/${crateName} --emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow | ||
fi | ||
mkdir -p target/build/${crateName}.out | ||
export RUST_BACKTRACE=1 | ||
BUILD_OUT_DIR="-L $OUT_DIR" | ||
mkdir -p $OUT_DIR | ||
target/build/${crateName}/build_script_build > target/build/${crateName}.opt | ||
set +e | ||
EXTRA_BUILD=$(grep "^cargo:rustc-flags=" target/build/${crateName}.opt | sed -e "s/cargo:rustc-flags=\(.*\)/\1/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is both |
||
EXTRA_FEATURES=$(grep "^cargo:rustc-cfg=" target/build/${crateName}.opt | sed -e "s/cargo:rustc-cfg=\(.*\)/--cfg \1/") | ||
|
||
EXTRA_LINK=$(grep "^cargo:rustc-link-lib=" target/build/${crateName}.opt | sed -e "s/cargo:rustc-link-lib=\(.*\)/\1/") | ||
EXTRA_LINK_SEARCH=$(grep "^cargo:rustc-link-search=" target/build/${crateName}.opt | sed -e "s/cargo:rustc-link-search=\(.*\)/\1/") | ||
CRATENAME=$(echo ${crateName} | sed -e "s/\(.*\)-sys$/\1/" | tr '[:lower:]' '[:upper:]') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. - CRATENAME=$(echo ${crateName} | sed -e "s/\(.*\)-sys$/\1/" | tr '[:lower:]' '[:upper:]')
+ CRATENAME=$(echo ${crateName} | sed -e "s/\(.*\)-sys$/\U\1/") |
||
|
||
grep "^cargo:" target/build/${crateName}.opt | grep -v "^cargo:rustc-" | grep -v "^cargo:warning=" | grep -v "^cargo:rerun-if-changed=" | grep -v "^cargo:rerun-if-env-changed" | sed -e "s/cargo:\([^=]*\)=\(.*\)/export DEP_$(echo $CRATENAME)_\U\1\E=\2/" > target/env | ||
|
||
set -e | ||
if [ -n "$(ls target/build/${crateName}.out)" ]; then | ||
|
||
if [ -e "${libPath}" ] ; then | ||
cp -r target/build/${crateName}.out/* $(dirname ${libPath}) #*/ | ||
else | ||
cp -r target/build/${crateName}.out/* src #*/ | ||
fi | ||
fi | ||
fi | ||
# echo "Features: ${crateFeatures}" $EXTRA_FEATURES | ||
|
||
EXTRA_LIB="" | ||
CRATE_NAME=$(echo ${libName} | sed -e "s/-/_/g") | ||
# echo "Libname" ${libName} ${libPath} | ||
# echo "Deps: ${deps}" | ||
if [ -e "${libPath}" ] ; then | ||
|
||
echo "$boldgreen" "Building ${libPath}" "$norm" | ||
if ${verboseBuild}; then | ||
echo "$boldgreen" "Running" "$norm" "rustc --crate-name $CRATE_NAME ${libPath} --crate-type ${crateType} ${rustcOpts} ${rustcMeta} ${crateFeatures} --out-dir target/deps --emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES" | ||
fi | ||
rustc --crate-name $CRATE_NAME ${libPath} --crate-type ${crateType} ${rustcOpts} ${rustcMeta} ${crateFeatures} --out-dir target/deps --emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES | ||
EXTRA_LIB=" --extern $CRATE_NAME=target/deps/lib$CRATE_NAME-${metadata}.rlib" | ||
if [ -e target/deps/lib$CRATE_NAME-${metadata}.so ]; then | ||
EXTRA_LIB="$EXTRA_LIB --extern $CRATE_NAME=target/deps/lib$CRATE_NAME-${metadata}.so" | ||
fi | ||
elif [ -e src/lib.rs ] ; then | ||
|
||
echo "$boldgreen" "Building src/lib.rs (${libName})" "$norm" | ||
if ${verboseBuild}; then | ||
echo "$boldgreen" "Running" "$norm" "rustc --crate-name $CRATE_NAME src/lib.rs --crate-type ${crateType} ${rustcOpts} ${rustcMeta} ${crateFeatures} --out-dir target/deps --emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES"; | ||
fi | ||
|
||
rustc --crate-name $CRATE_NAME src/lib.rs --crate-type ${crateType} ${rustcOpts} ${rustcMeta} ${crateFeatures} --out-dir target/deps --emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES | ||
EXTRA_LIB=" --extern $CRATE_NAME=target/deps/lib$CRATE_NAME-${metadata}.rlib" | ||
if [ -e target/deps/lib$CRATE_NAME-${metadata}.so ]; then | ||
EXTRA_LIB="$EXTRA_LIB --extern $CRATE_NAME=target/deps/lib$CRATE_NAME-${metadata}.so" | ||
fi | ||
|
||
elif [ -e src/${libName}.rs ] ; then | ||
|
||
echo "$boldgreen" "Building src/${libName}.rs" "$norm" | ||
|
||
if ${verboseBuild}; then | ||
echo "rustc --crate-name $CRATE_NAME src/${libName}.rs --crate-type ${crateType} ${rustcOpts} ${rustcMeta} ${crateFeatures} --out-dir target/deps --emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES" | ||
fi | ||
|
||
rustc --crate-name $CRATE_NAME src/${libName}.rs --crate-type ${crateType} ${rustcOpts} ${rustcMeta} ${crateFeatures} --out-dir target/deps --emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES | ||
EXTRA_LIB=" --extern $CRATE_NAME=target/deps/lib$CRATE_NAME-${metadata}.rlib" | ||
if [ -e target/deps/lib$CRATE_NAME-${metadata}.so ]; then | ||
EXTRA_LIB="$EXTRA_LIB --extern $CRATE_NAME=target/deps/lib$CRATE_NAME-${metadata}.so" | ||
fi | ||
|
||
fi | ||
|
||
echo "$EXTRA_LINK_SEARCH" | while read i; do | ||
if [ ! -z "$i" ]; then | ||
echo "-L $i" >> target/link | ||
L=$(echo $i | sed -e "s#$(pwd)/target/build#$out#") | ||
echo "-L $L" >> target/link.final | ||
fi | ||
done | ||
echo "$EXTRA_LINK" | while read i; do | ||
if [ ! -z "$i" ]; then | ||
echo "-l $i" >> target/link | ||
echo "-l $i" >> target/link.final | ||
fi | ||
done | ||
|
||
if [ -e target/link ]; then | ||
sort -u target/link.final > target/link.final.sorted | ||
mv target/link.final.sorted target/link.final | ||
sort -u target/link > target/link.sorted | ||
mv target/link.sorted target/link | ||
|
||
tr '\n' ' ' < target/link > target/link_ | ||
LINK=$(cat target/link_) | ||
fi | ||
|
||
mkdir -p target/bin | ||
echo "${crateBin}" | sed -n 1'p' | tr ',' '\n' | while read BIN; do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
- echo "${crateBin}" | sed -n 1'p' | tr ',' '\n' | while read BIN; do
+ echo "${crateBin}" | head -n 1 | tr ',' '\n' | while read BIN; do UPDATE the above does something else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this actually needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could |
||
if [ ! -z "$BIN" ]; then | ||
printf "%s" "$boldgreen" | ||
echo "Building $BIN" | ||
printf "%s" "$norm" | ||
if ${verboseBuild}; then | ||
echo "$boldgreen" "Running" "$norm" " rustc --crate-name $BIN --crate-type bin ${rustcOpts} ${crateFeatures} --out-dir target/bin --emit=dep-info,link -L dependency=target/deps $LINK ${deps}$EXTRA_LIB --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES" | ||
fi | ||
rustc --crate-name $BIN --crate-type bin ${rustcOpts} ${crateFeatures} --out-dir target/bin --emit=dep-info,link -L dependency=target/deps $LINK ${deps}$EXTRA_LIB --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES | ||
fi | ||
done | ||
if [[ (-z "${crateBin}") && (-e src/main.rs) ]]; then | ||
printf "%s" "$boldgreen" | ||
echo "Building src/main.rs" | ||
printf "%s" "$norm" | ||
if ${verboseBuild}; then | ||
echo "$boldgreen" "Running" "$norm" "rustc --crate-name $CRATE_NAME src/main.rs --crate-type bin ${rustcOpts} ${crateFeatures} --out-dir target/bin --emit=dep-info,link -L dependency=target/deps $LINK ${deps}$EXTRA_LIB --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES" | ||
fi | ||
rustc --crate-name $CRATE_NAME src/main.rs --crate-type bin ${rustcOpts} ${crateFeatures} --out-dir target/bin --emit=dep-info,link -L dependency=target/deps $LINK ${deps}$EXTRA_LIB --cap-lints allow $BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cargo will also build any file in diff --git a/pkgs/build-support/rust/rust-utils.nix b/pkgs/build-support/rust/rust-utils.nix
index 0e9458bab11..5070186f07c 100644
--- a/pkgs/build-support/rust/rust-utils.nix
+++ b/pkgs/build-support/rust/rust-utils.nix
@@ -257,9 +257,14 @@ let buildCrate = { crateName, crateVersion, crateAuthors, buildDependencies,
build_bin $BIN
fi
done
- if [[ (-z "${crateBin}") && (-e src/main.rs) ]]; then
- build_bin ${crateName} src/main.rs
- fi
+ ${lib.optionalString (crateBin == "") ''
+ if [[ -e src/main.rs ]]; then
+ build_bin ${crateName} src/main.rs
+ fi
+ for i in src/bin/*.rs; do
+ build_bin "$(basename $i .rs)" "$i"
+ done
+ ''}
# Remove object files to avoid "wrong ELF type"
find target -type f -name "*.o" -print0 | xargs -0 rm -f
runHook postBuild tested with ofborg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, cargo doesn't always build There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nightmare. How do we handle this? Without good multiple-binary support, this patchset feels not useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mentioned the FYI only because I don't fully understand how this patch set works... yet, and wanted to make sure this wasn't overlooked. It may already be handled. I have a Rust project I'm packaging to run on NixOS that has two The best I can figure is carnix emulates cargo's behavior here. Carnix does parse the Cargo.toml and if it finds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see, if I declared my binaries in the Cargo.toml it wouldn't require this patch? Great! Makes sense, thank you for the clarification. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To better illustrate my example, here's a gist [1] of the carnix output for my project. Towards the bottom is a more condensed version with a layout of my project directory. The I'll run a few more tests and report back. [1]: https://gist.github.com/boxofrox/59b0a7fe4cce97e9c5753aee50bd25d9 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @boxofrox yes, you are right, we do the same as cargo and skip building There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great. And the tests I ran--disabling some and all |
||
'' + finalBins; | ||
|
||
installCrate = crateName: '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same for
|
||
mkdir -p $out | ||
if [ -s target/env ]; then | ||
cp target/env $out/env | ||
fi | ||
if [ -s target/link.final ]; then | ||
cp target/link.final $out/link | ||
fi | ||
cp target/deps/* $out # */ | ||
if [ "$(ls -A target/build)" ]; then # */ | ||
cp -r target/build/* $out # */ | ||
fi | ||
if [ "$(ls -A target/bin)" ]; then # */ | ||
mkdir -p $out/bin | ||
cp -P target/bin/* $out/bin # */ | ||
fi | ||
''; | ||
in | ||
|
||
crate: rust: stdenv.mkDerivation rec { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see why you have added these parameter (to use different rust versions). But should this not be also possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe many Rust users use the default Rust from nixpkgs (of course, I might be wrong), since the overlay is much more convenient. What are the pros and cons of doing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is the documented way to override dependencies in derivations. If you want your own version of this function, you would do: my-rust-crates = callPackage ../my-rust-crates {
mkRustCrate = mkRustCrate.override ({rust = rustNightly;})
}; It would not limit what rust developer would like to use as a rust version, but still sets a default for nixpkgs and non-developer, who just want to build a rust application. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be useful as there are some features only available on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! It is actually more elegant (even though I had to modify all my projects' default.nix). |
||
|
||
inherit (crate) crateName src; | ||
|
||
release = if crate ? release then crate.release else false; | ||
name = "rust_${crate.crateName}-${crate.version}"; | ||
buildInputs = [ rust ] ++ (lib.attrByPath ["buildInputs"] [] crate); | ||
dependencies = builtins.map (dep: dep rust) (lib.attrByPath ["dependencies"] [] crate); | ||
|
||
complete = builtins.foldl' (comp: dep: if lib.lists.any (x: x == comp) dep.complete then comp ++ dep.complete else comp) dependencies dependencies; | ||
|
||
crateFeatures = if crate ? features then | ||
builtins.foldl' (features: f: features + " --cfg feature=\\\"${f}\\\"") "" crate.features | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be also replaced by |
||
else ""; | ||
|
||
libName = if crate ? libName then crate.libName else crate.crateName; | ||
libPath = if crate ? libPath then crate.libPath else ""; | ||
|
||
metadata = builtins.substring 0 10 (builtins.hashString "sha256" (crateName + "-" + crateVersion)); | ||
|
||
crateBin = if crate ? crateBin then | ||
builtins.foldl' (bins: bin: | ||
let name = | ||
lib.strings.replaceStrings ["-"] ["_"] | ||
(if bin ? name then bin.name else crateName); | ||
path = if bin ? path then bin.path else "src/main.rs"; | ||
in | ||
bins + (if bin == "" then "" else ",") + "${name} ${path}" | ||
|
||
) "" crate.crateBin | ||
else ""; | ||
|
||
finalBins = if crate ? crateBin then | ||
builtins.foldl' (bins: bin: | ||
let name = lib.strings.replaceStrings ["-"] ["_"] | ||
(if bin ? name then bin.name else crateName); | ||
new_name = if bin ? name then bin.name else crateName; | ||
in | ||
if name == new_name then bins else | ||
(bins + "mv target/bin/${name} target/bin/${new_name};") | ||
|
||
) "" crate.crateBin | ||
else ""; | ||
|
||
build = if crate ? build then crate.build else ""; | ||
crateVersion = crate.version; | ||
crateType = | ||
if lib.attrByPath ["procMacro"] false crate then "proc-macro" else | ||
if lib.attrByPath ["plugin"] false crate then "dylib" else "lib"; | ||
verboseBuild = if lib.attrByPath [ "verbose" ] false crate then "true" else "false"; | ||
buildPhase = buildCrate { inherit crateName dependencies complete crateFeatures libName build release libPath crateType crateVersion metadata crateBin finalBins verboseBuild; }; | ||
installPhase = installCrate crateName; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6215,6 +6215,8 @@ with pkgs; | |
rust = callPackage ../development/compilers/rust { }; | ||
inherit (rust) cargo rustc; | ||
|
||
mkRustCrate = callPackage ../build-support/rust/rust-utils.nix { }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually try to avoid those discussion about naming things. Would like to stay with the name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This solution only builds rust crates? There are other artefacts possible such as shared objects. by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ultimately, this solution should build anything There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes indeed it does, I use your solution on my projects too. Though it's customized. I'll probably be removing that code in favour of this code. I renamed it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, changed the name to |
||
|
||
rustPlatform = recurseIntoAttrs (makeRustPlatform rust); | ||
|
||
makeRustPlatform = rust: lib.fix (self: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have https://github.com/NixOS/nixpkgs/blob/master/COPYING
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be then MIT, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the copyright notice, it's indeed MIT. Is there a contributors list somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a maintainers list in
lib/maintainers.nix
, when you add yourself to a package as maintainer inmeta.maintainers
.