cargo2nix unstable (patched), rust 1.63.0, nixpkgs 22.05 (32-bit builds are broken)

This commit is contained in:
Alex Auvolat 2022-10-13 14:35:39 +02:00
parent a096ced355
commit 8d04ae7014
No known key found for this signature in database
GPG key ID: 0E496D15096376BE
8 changed files with 1289 additions and 2533 deletions

34
Cargo.lock generated
View file

@ -248,7 +248,7 @@ dependencies = [
"hyper", "hyper",
"hyper-rustls", "hyper-rustls",
"lazy_static", "lazy_static",
"pin-project 1.0.10", "pin-project 1.0.12",
"pin-project-lite", "pin-project-lite",
"tokio", "tokio",
"tower", "tower",
@ -281,7 +281,7 @@ dependencies = [
"http-body", "http-body",
"hyper", "hyper",
"percent-encoding", "percent-encoding",
"pin-project 1.0.10", "pin-project 1.0.12",
"tokio", "tokio",
"tokio-util 0.6.9", "tokio-util 0.6.9",
"tracing", "tracing",
@ -297,7 +297,7 @@ dependencies = [
"bytes", "bytes",
"http", "http",
"http-body", "http-body",
"pin-project 1.0.10", "pin-project 1.0.12",
"tower", "tower",
"tracing", "tracing",
] ]
@ -1054,7 +1054,7 @@ dependencies = [
"opentelemetry", "opentelemetry",
"opentelemetry-prometheus", "opentelemetry-prometheus",
"percent-encoding", "percent-encoding",
"pin-project 1.0.10", "pin-project 1.0.12",
"prometheus", "prometheus",
"quick-xml", "quick-xml",
"roxmltree", "roxmltree",
@ -1731,7 +1731,7 @@ dependencies = [
"kube-core", "kube-core",
"openssl", "openssl",
"pem", "pem",
"pin-project 1.0.10", "pin-project 1.0.12",
"serde", "serde",
"serde_json", "serde_json",
"serde_yaml", "serde_yaml",
@ -1786,7 +1786,7 @@ dependencies = [
"json-patch", "json-patch",
"k8s-openapi", "k8s-openapi",
"kube-client", "kube-client",
"pin-project 1.0.10", "pin-project 1.0.12",
"serde", "serde",
"serde_json", "serde_json",
"smallvec", "smallvec",
@ -2050,7 +2050,7 @@ dependencies = [
"log", "log",
"opentelemetry", "opentelemetry",
"opentelemetry-contrib", "opentelemetry-contrib",
"pin-project 1.0.10", "pin-project 1.0.12",
"rand 0.8.5", "rand 0.8.5",
"rmp-serde", "rmp-serde",
"serde", "serde",
@ -2187,7 +2187,7 @@ dependencies = [
"js-sys", "js-sys",
"lazy_static", "lazy_static",
"percent-encoding", "percent-encoding",
"pin-project 1.0.10", "pin-project 1.0.12",
"rand 0.8.5", "rand 0.8.5",
"thiserror", "thiserror",
"tokio", "tokio",
@ -2382,11 +2382,11 @@ dependencies = [
[[package]] [[package]]
name = "pin-project" name = "pin-project"
version = "1.0.10" version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc"
dependencies = [ dependencies = [
"pin-project-internal 1.0.10", "pin-project-internal 1.0.12",
] ]
[[package]] [[package]]
@ -2402,9 +2402,9 @@ dependencies = [
[[package]] [[package]]
name = "pin-project-internal" name = "pin-project-internal"
version = "1.0.10" version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -3615,7 +3615,7 @@ dependencies = [
"hyper", "hyper",
"hyper-timeout", "hyper-timeout",
"percent-encoding", "percent-encoding",
"pin-project 1.0.10", "pin-project 1.0.12",
"prost", "prost",
"prost-derive", "prost-derive",
"tokio", "tokio",
@ -3649,7 +3649,7 @@ dependencies = [
"futures-core", "futures-core",
"futures-util", "futures-util",
"indexmap", "indexmap",
"pin-project 1.0.10", "pin-project 1.0.12",
"pin-project-lite", "pin-project-lite",
"rand 0.8.5", "rand 0.8.5",
"slab", "slab",
@ -3672,7 +3672,7 @@ dependencies = [
"futures-util", "futures-util",
"http", "http",
"http-body", "http-body",
"pin-project 1.0.10", "pin-project 1.0.12",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
"tracing", "tracing",
@ -3730,7 +3730,7 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
dependencies = [ dependencies = [
"pin-project 1.0.10", "pin-project 1.0.12",
"tracing", "tracing",
] ]

3613
Cargo.nix

File diff suppressed because it is too large Load diff

View file

@ -8,10 +8,23 @@ with import ./nix/common.nix;
let let
pkgs = import pkgsSrc { }; pkgs = import pkgsSrc { };
compile = import ./nix/compile.nix; compile = import ./nix/compile.nix;
build_debug_and_release = (target: { build_debug_and_release = (target: {
debug = (compile { inherit target git_version; release = false; }).workspace.garage { compileMode = "build"; }; debug = (compile {
release = (compile { inherit target git_version; release = true; }).workspace.garage { compileMode = "build"; }; inherit target git_version;
release = false;
}).workspace.garage {
compileMode = "build";
};
release = (compile {
inherit target git_version;
release = true;
}).workspace.garage {
compileMode = "build";
};
}); });
test = (rustPkgs: pkgs.symlinkJoin { test = (rustPkgs: pkgs.symlinkJoin {
name ="garage-tests"; name ="garage-tests";
paths = builtins.map (key: rustPkgs.workspace.${key} { compileMode = "test"; }) (builtins.attrNames rustPkgs.workspace); paths = builtins.map (key: rustPkgs.workspace.${key} { compileMode = "test"; }) (builtins.attrNames rustPkgs.workspace);
@ -25,9 +38,23 @@ in {
arm = build_debug_and_release "armv6l-unknown-linux-musleabihf"; arm = build_debug_and_release "armv6l-unknown-linux-musleabihf";
}; };
test = { test = {
amd64 = test (compile { inherit git_version; target = "x86_64-unknown-linux-musl"; }); amd64 = test (compile {
inherit git_version;
target = "x86_64-unknown-linux-musl";
features = [
"garage/bundled-libs"
"garage/sled"
"garage/k2v"
"garage/lmdb"
"garage/sqlite"
];
});
}; };
clippy = { clippy = {
amd64 = (compile { inherit git_version; compiler = "clippy"; }).workspace.garage { compileMode = "build"; } ; amd64 = (compile {
inherit git_version;
target = "x86_64-unknown-linux-musl";
compiler = "clippy";
}).workspace.garage {} ;
}; };
} }

View file

@ -4,19 +4,27 @@ rec {
*/ */
pkgsSrc = fetchTarball { pkgsSrc = fetchTarball {
# As of 2021-10-04 # As of 2021-10-04
url = "https://github.com/NixOS/nixpkgs/archive/b27d18a412b071f5d7991d1648cfe78ee7afe68a.tar.gz"; #url = "https://github.com/NixOS/nixpkgs/archive/b27d18a412b071f5d7991d1648cfe78ee7afe68a.tar.gz";
sha256 = "1xy9zpypqfxs5gcq5dcla4bfkhxmh5nzn9dyqkr03lqycm9wg5cr"; #sha256 = "1xy9zpypqfxs5gcq5dcla4bfkhxmh5nzn9dyqkr03lqycm9wg5cr";
# NixOS 22.05
url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/22.05.zip";
sha256 = "0d643wp3l77hv2pmg2fi7vyxn4rwy0iyr8djcw1h5x72315ck9ik";
# As of 2022-10-13
#url = "https://github.com/NixOS/nixpkgs/archive/a3073c49bc0163fea6a121c276f526837672b555.zip";
#sha256 = "1bz632psfbpmicyzjb8b4265y50shylccvfm6ry6mgnv5hvz324s";
}; };
cargo2nixSrc = fetchGit { cargo2nixSrc = fetchGit {
# As of 2022-08-29, stacking two patches: superboum@dedup_propagate and Alexis211@fix_fetchcrategit # As of 2022-10-14: (TODO)
url = "https://github.com/Alexis211/cargo2nix"; url = "https://github.com/Alexis211/cargo2nix";
ref = "fix_fetchcrategit"; ref = "custom_unstable";
rev = "4b31c0cc05b6394916d46e9289f51263d81973b9"; rev = "15543df35485bef9e2092391ecafa78eae5fa740";
}; };
/* /*
* Shared objects * Shared objects
*/ */
cargo2nix = import cargo2nixSrc; cargo2nix = import cargo2nixSrc;
cargo2nixOverlay = import "${cargo2nixSrc}/overlay"; cargo2nixOverlay = cargo2nix.overlays.default;
} }

View file

@ -1,9 +1,10 @@
{ {
system ? builtins.currentSystem, system ? builtins.currentSystem,
target ? null, target,
compiler ? "rustc", compiler ? "rustc",
release ? false, release ? false,
git_version ? null, git_version ? null,
features ? null,
}: }:
with import ./common.nix; with import ./common.nix;
@ -13,19 +14,12 @@ let
pkgs = import pkgsSrc { pkgs = import pkgsSrc {
inherit system; inherit system;
${ if target == null then null else "crossSystem" } = { config = target; }; crossSystem = {
config = target;
};
overlays = [ cargo2nixOverlay ]; overlays = [ cargo2nixOverlay ];
}; };
/*
Rust and Nix triples are not the same. Cargo2nix has a dedicated library
to convert Nix triples to Rust ones. We need this conversion as we want to
set later options linked to our (rust) target in a generic way. Not only
the triple terminology is different, but also the "roles" are named differently.
Nix uses a build/host/target terminology where Nix's "host" maps to Cargo's "target".
*/
rustTarget = log (pkgs.rustBuilder.rustLib.rustTriple pkgs.stdenv.hostPlatform);
/* /*
Cargo2nix is built for rustOverlay which installs Rust from Mozilla releases. Cargo2nix is built for rustOverlay which installs Rust from Mozilla releases.
We want our own Rust to avoid incompatibilities, like we had with musl 1.2.0. We want our own Rust to avoid incompatibilities, like we had with musl 1.2.0.
@ -37,7 +31,8 @@ let
In practise, rustOverlay ships rustc+cargo in a single derivation while In practise, rustOverlay ships rustc+cargo in a single derivation while
NixOS ships them in separate ones. We reunite them with symlinkJoin. NixOS ships them in separate ones. We reunite them with symlinkJoin.
*/ */
rustChannel = { /*
rustToolchain = {
rustc = pkgs.symlinkJoin { rustc = pkgs.symlinkJoin {
name = "rust-channel"; name = "rust-channel";
paths = [ paths = [
@ -54,29 +49,7 @@ let
]; ];
}; };
}.${compiler}; }.${compiler};
*/
clippyBuilder = pkgs.writeScriptBin "clippy" ''
#!${pkgs.stdenv.shell}
. ${cargo2nixSrc + "/overlay/utils.sh"}
isBuildScript=
args=("$@")
for i in "''${!args[@]}"; do
if [ "xmetadata=" = "x''${args[$i]::9}" ]; then
args[$i]=metadata=$NIX_RUST_METADATA
elif [ "x--crate-name" = "x''${args[$i]}" ] && [ "xbuild_script_" = "x''${args[$i+1]::13}" ]; then
isBuildScript=1
fi
done
if [ "$isBuildScript" ]; then
args+=($NIX_RUST_BUILD_LINK_FLAGS)
else
args+=($NIX_RUST_LINK_FLAGS)
fi
touch invoke.log
echo "''${args[@]}" >>invoke.log
exec ${rustChannel}/bin/clippy-driver --deny warnings "''${args[@]}"
'';
buildEnv = (drv: { buildEnv = (drv: {
rustc = drv.setBuildEnv; rustc = drv.setBuildEnv;
@ -86,7 +59,8 @@ let
echo --- BUILDING WITH CLIPPY --- echo --- BUILDING WITH CLIPPY ---
echo echo
export RUSTC=${clippyBuilder}/bin/clippy export NIX_RUST_BUILD_FLAGS="''${NIX_RUST_BUILD_FLAGS} --deny warnings"
export RUSTC="''${CLIPPY_DRIVER}"
''; '';
}.${compiler}); }.${compiler});
@ -97,7 +71,7 @@ let
You can have a complete list of the available options by looking at the overriden object, mkcrate: You can have a complete list of the available options by looking at the overriden object, mkcrate:
https://github.com/cargo2nix/cargo2nix/blob/master/overlay/mkcrate.nix https://github.com/cargo2nix/cargo2nix/blob/master/overlay/mkcrate.nix
*/ */
overrides = pkgs.rustBuilder.overrides.all ++ [ packageOverrides = pkgs: pkgs.rustBuilder.overrides.all ++ [
/* /*
[1] We add some logic to compile our crates with clippy, it provides us many additional lints [1] We add some logic to compile our crates with clippy, it provides us many additional lints
@ -113,12 +87,7 @@ let
As we do not want to consider the .git folder as part of the input source, As we do not want to consider the .git folder as part of the input source,
we ask the user (the CI often) to pass the value to Nix. we ask the user (the CI often) to pass the value to Nix.
[4] We ship some parts of the code disabled by default by putting them behind a flag. [4] We don't want libsodium-sys and zstd-sys to try to use pkgconfig to build against a system library.
It speeds up the compilation (when the feature is not required) and released crates have less dependency by default (less attack surface, disk space, etc.).
But we want to ship these additional features when we release Garage.
In the end, we chose to exclude all features from debug builds while putting (all of) them in the release builds.
[5] We don't want libsodium-sys and zstd-sys to try to use pkgconfig to build against a system library.
However the features to do so get activated for some reason (due to a bug in cargo2nix?), However the features to do so get activated for some reason (due to a bug in cargo2nix?),
so disable them manually here. so disable them manually here.
*/ */
@ -136,10 +105,6 @@ let
/* [1] */ setBuildEnv = (buildEnv drv); /* [1] */ setBuildEnv = (buildEnv drv);
/* [2] */ hardeningDisable = [ "pie" ]; /* [2] */ hardeningDisable = [ "pie" ];
}; };
overrideArgs = old: {
/* [4] */ features = [ "bundled-libs" "sled" "metrics" "k2v" ]
++ (if release then [ "kubernetes-discovery" "telemetry-otlp" "lmdb" "sqlite" ] else []);
};
}) })
(pkgs.rustBuilder.rustLib.makeOverride { (pkgs.rustBuilder.rustLib.makeOverride {
@ -190,18 +155,38 @@ let
(pkgs.rustBuilder.rustLib.makeOverride { (pkgs.rustBuilder.rustLib.makeOverride {
name = "libsodium-sys"; name = "libsodium-sys";
overrideArgs = old: { overrideArgs = old: {
features = [ ]; /* [5] */ features = [ ]; /* [4] */
}; };
}) })
(pkgs.rustBuilder.rustLib.makeOverride { (pkgs.rustBuilder.rustLib.makeOverride {
name = "zstd-sys"; name = "zstd-sys";
overrideArgs = old: { overrideArgs = old: {
features = [ ]; /* [5] */ features = [ ]; /* [4] */
}; };
}) })
]; ];
/*
We ship some parts of the code disabled by default by putting them behind a flag.
It speeds up the compilation (when the feature is not required) and released crates have less dependency by default (less attack surface, disk space, etc.).
But we want to ship these additional features when we release Garage.
In the end, we chose to exclude all features from debug builds while putting (all of) them in the release builds.
*/
rootFeatures = if features != null then features else
([
"garage/bundled-libs"
"garage/sled"
"garage/k2v"
] ++ (if release then [
"garage/kubernetes-discovery"
"garage/metrics"
"garage/telemetry-otlp"
"garage/lmdb"
"garage/sqlite"
] else []));
packageFun = import ../Cargo.nix; packageFun = import ../Cargo.nix;
/* /*
@ -222,23 +207,20 @@ let
"x86_64-unknown-linux-musl" = [ "target-feature=+crt-static" "link-arg=-static-pie" ]; "x86_64-unknown-linux-musl" = [ "target-feature=+crt-static" "link-arg=-static-pie" ];
}; };
in
/* /*
The following definition is not elegant as we use a low level function of Cargo2nix NixOS and Rust/Cargo triples do not match for ARM, fix it here.
that enables us to pass our custom rustChannel object. We need this low level definition
to pass Nix's Rust toolchains instead of Mozilla's one.
target is mandatory but must be kept to null to allow cargo2nix to set it to the appropriate value
for each crate.
*/ */
pkgs.rustBuilder.makePackageSet { rustTarget = if target == "armv6l-unknown-linux-musleabihf"
inherit packageFun rustChannel release codegenOpts; then "arm-unknown-linux-musleabihf"
packageOverrides = overrides; else target;
target = null;
buildRustPackages = pkgs.buildPackages.rustBuilder.makePackageSet { in
inherit rustChannel packageFun codegenOpts; pkgs.rustBuilder.makePackageSet {
packageOverrides = overrides; inherit release packageFun packageOverrides codegenOpts rootFeatures;
target = null;
}; #inherit rustToolchain;
rustVersion = "1.63.0";
target = rustTarget;
extraRustComponents = [ "clippy" ];
} }

View file

@ -14,18 +14,22 @@ let
pkgsList = builtins.map (target: import pkgsSrc { pkgsList = builtins.map (target: import pkgsSrc {
inherit system; inherit system;
crossSystem = { config = target; }; crossSystem = { config = target; };
overlays = [ cargo2nixOverlay ];
}) platforms; }) platforms;
pkgsHost = import pkgsSrc {}; pkgsHost = import pkgsSrc {};
lib = pkgsHost.lib; lib = pkgsHost.lib;
kaniko = (import ./kaniko.nix) pkgsHost; kaniko = (import ./kaniko.nix) pkgsHost;
winscp = (import ./winscp.nix) pkgsHost; winscp = (import ./winscp.nix) pkgsHost;
manifestTool = (import ./manifest-tool.nix) pkgsHost;
in in
lib.flatten (builtins.map (pkgs: [ lib.flatten (builtins.map (pkgs: [
pkgs.rustPlatform.rust.rustc pkgs.rustPlatform.rust.rustc
pkgs.rustPlatform.rust.cargo pkgs.rustPlatform.rust.cargo
pkgs.clippy
pkgs.buildPackages.stdenv.cc pkgs.buildPackages.stdenv.cc
]) pkgsList) ++ [ ]) pkgsList) ++ [
kaniko kaniko
winscp winscp
manifestTool
] ]

View file

@ -36,7 +36,7 @@ sha2 = "0.10"
futures = "0.3" futures = "0.3"
futures-util = "0.3" futures-util = "0.3"
pin-project = "1.0" pin-project = "1.0.11"
tokio = { version = "1.0", default-features = false, features = ["rt", "rt-multi-thread", "io-util", "net", "time", "macros", "sync", "signal", "fs"] } tokio = { version = "1.0", default-features = false, features = ["rt", "rt-multi-thread", "io-util", "net", "time", "macros", "sync", "signal", "fs"] }
tokio-stream = "0.1" tokio-stream = "0.1"

View file

@ -318,7 +318,7 @@ fn path_to_key<'a>(path: &'a str, index: &str) -> Result<Cow<'a, str>, Error> {
} }
Some(_) => match path_utf8 { Some(_) => match path_utf8 {
Cow::Borrowed(pu8) => Ok((&pu8[1..]).into()), Cow::Borrowed(pu8) => Ok((&pu8[1..]).into()),
Cow::Owned(pu8) => Ok((&pu8[1..]).to_string().into()), Cow::Owned(pu8) => Ok(pu8[1..].to_string().into()),
}, },
} }
} }