refactor: Refactor tests into separate files

This commit is contained in:
Patryk Wychowaniec 2022-05-02 18:23:16 +02:00
parent e8f9f8d037
commit f21309b38e
106 changed files with 365 additions and 1109 deletions

View file

View file

@ -1,22 +0,0 @@
import ./default.nix {
rustcVersion = "1.38.0";
rustcSha256 = "101dlpsfkq67p0hbwx4acqq6n90dj4bbprndizpgh1kigk566hk4";
enableRustcDev = false;
# Note: the version MUST be one version prior to the version we're
# building
bootstrapVersion = "1.37.0";
# fetch hashes by running `print-hashes.sh 1.37.0`
bootstrapHashes = {
i686-unknown-linux-gnu = "74510e0e52a55e65a9f716673c2cda4d2bd427e2453541c6993c77c3ec04acf9";
x86_64-unknown-linux-gnu = "cb573229bfd32928177c3835fdeb62d52da64806b844bc1095c6225b0665a1cb";
arm-unknown-linux-gnueabihf = "272739fbb23cf6c2040c1813af9c8c7f386cac37d9de638f22a1816eb96bc0ae";
armv7-unknown-linux-gnueabihf = "5b87b877f0ed20c6a09ce26e7a15d8c61b26b62484b97e78a51099d0efefec98";
aarch64-unknown-linux-gnu = "263ef98fa3a6b2911b56f89c06615cdebf6ef676eb9b2493ad1539602f79b6ba";
i686-apple-darwin = "e45d0c4d882fc6c404ffa6fe790294f4ea96384a2b48804adbf723f3635477a8";
x86_64-apple-darwin = "b2310c97ffb964f253c4088c8d29865f876a49da2a45305493af5b5c7a3ca73d";
};
selectRustPackage = pkgs: pkgs.rust_1_38_0;
}

View file

@ -1,30 +0,0 @@
# New rust versions should first go to staging.
# Things to check after updating:
# 1. Rustc should produce rust binaries on x86_64-linux, aarch64-linux and x86_64-darwin:
# i.e. nix-shell -p fd or @GrahamcOfBorg build fd on github
# This testing can be also done by other volunteers as part of the pull
# request review, in case platforms cannot be covered.
# 2. The LLVM version used for building should match with rust upstream.
# 3. Firefox and Thunderbird should still build on x86_64-linux.
import ./default.nix {
rustcVersion = "1.41.0";
rustcSha256 = "0jypz2mrzac41sj0zh07yd1z36g2s2rvgsb8g624sk4l14n84ijm";
# Note: the version MUST be one version prior to the version we're
# building
bootstrapVersion = "1.40.0";
# fetch hashes by running `print-hashes.sh 1.40.0`
bootstrapHashes = {
i686-unknown-linux-gnu = "d050d3a1c7c45ba9c50817d45bf6d7dd06e1a4d934f633c8096b7db6ae27adc1";
x86_64-unknown-linux-gnu = "fc91f8b4bd18314e83a617f2389189fc7959146b7177b773370d62592d4b07d0";
arm-unknown-linux-gnueabihf = "4be9949c4d3c572b69b1df61c3506a3a3ac044851f025d38599612e7caa933c5";
armv7-unknown-linux-gnueabihf = "ebfe3978e12ffe34276272ee6d0703786249a9be80ca50617709cbfdab557306";
aarch64-unknown-linux-gnu = "639271f59766d291ebdade6050e7d05d61cb5c822a3ef9a1e2ab185fed68d729";
i686-apple-darwin = "ea189b1fb0bfda367cde6d43c18863ab4c64ffca04265e5746bf412a186fe1a2";
x86_64-apple-darwin = "749ca5e0b94550369cc998416b8854c13157f5d11d35e9b3276064b6766bcb83";
};
selectRustPackage = pkgs: pkgs.rust_1_41_0;
}

View file

@ -1,102 +0,0 @@
{ stdenv, lib, makeWrapper, bash, curl, darwin
, version
, src
, platform
, versionType
}:
let
inherit (lib) optionalString;
inherit (darwin.apple_sdk.frameworks) Security;
bootstrapping = versionType == "bootstrap";
installComponents
= "rustc,rust-std-${platform}"
+ (optionalString bootstrapping ",cargo")
;
in
rec {
rustc = stdenv.mkDerivation {
name = "rustc-${versionType}-${version}";
inherit version;
inherit src;
meta = with lib; {
homepage = http://www.rust-lang.org/;
description = "A safe, concurrent, practical language";
maintainers = with maintainers; [ qknight ];
license = [ licenses.mit licenses.asl20 ];
};
buildInputs = [ bash ]
++ lib.optional stdenv.isDarwin Security;
postPatch = ''
patchShebangs .
'';
installPhase = ''
./install.sh --prefix=$out \
--components=${installComponents}
${optionalString (stdenv.isLinux && bootstrapping) ''
patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
"$out/bin/rustc"
patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
"$out/bin/rustdoc"
patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
"$out/bin/cargo"
''}
# Do NOT, I repeat, DO NOT use `wrapProgram` on $out/bin/rustc
# (or similar) here. It causes strange effects where rustc loads
# the wrong libraries in a bootstrap-build causing failures that
# are very hard to track down. For details, see
# https://github.com/rust-lang/rust/issues/34722#issuecomment-232164943
'';
setupHooks = ./setup-hook.sh;
};
cargo = stdenv.mkDerivation {
name = "cargo-${versionType}-${version}";
inherit version;
inherit src;
meta = with lib; {
homepage = http://www.rust-lang.org/;
description = "A safe, concurrent, practical language";
maintainers = with maintainers; [ qknight ];
license = [ licenses.mit licenses.asl20 ];
};
buildInputs = [ makeWrapper bash ]
++ lib.optional stdenv.isDarwin Security;
postPatch = ''
patchShebangs .
'';
installPhase = ''
patchShebangs ./install.sh
./install.sh --prefix=$out \
--components=cargo
${optionalString (stdenv.isLinux && bootstrapping) ''
patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
"$out/bin/cargo"
''}
wrapProgram "$out/bin/cargo" \
--suffix PATH : "${rustc}/bin"
'';
};
}

View file

@ -1,14 +0,0 @@
{ stdenv, fetchurl, rust, callPackage, version, hashes }:
let
platform = rust.toRustTarget stdenv.hostPlatform;
src = fetchurl {
url = "https://static.rust-lang.org/dist/rust-${version}-${platform}.tar.gz";
sha256 = hashes.${platform} or (throw "missing bootstrap url for platform ${platform}");
};
in callPackage ./binary.nix
{ inherit version src platform;
versionType = "bootstrap";
}

View file

@ -1,56 +0,0 @@
{ stdenv, lib, file, curl, pkg-config, python3, openssl, cmake, zlib
, makeWrapper, libiconv, cacert, rustPlatform, rustc, libgit2
, CoreFoundation, Security
}:
rustPlatform.buildRustPackage {
name = "cargo-${rustc.version}";
inherit (rustc) version src;
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
cargoVendorDir = "vendor";
preBuild = "pushd src/tools/cargo";
postBuild = "popd";
passthru.rustc = rustc;
# changes hash of vendor directory otherwise
dontUpdateAutotoolsGnuConfigScripts = true;
nativeBuildInputs = [ pkg-config cmake makeWrapper ];
buildInputs = [ cacert file curl python3 openssl zlib libgit2 ]
++ lib.optionals stdenv.isDarwin [ CoreFoundation Security libiconv ];
LIBGIT2_SYS_USE_PKG_CONFIG = 1;
# fixes: the cargo feature `edition` requires a nightly version of Cargo, but this is the `stable` channel
RUSTC_BOOTSTRAP = 1;
postInstall = ''
# NOTE: We override the `http.cainfo` option usually specified in
# `.cargo/config`. This is an issue when users want to specify
# their own certificate chain as environment variables take
# precedence
wrapProgram "$out/bin/cargo" \
--suffix PATH : "${rustc}/bin" \
--set CARGO_HTTP_CAINFO "${cacert}/etc/ssl/certs/ca-bundle.crt" \
--set SSL_CERT_FILE "${cacert}/etc/ssl/certs/ca-bundle.crt"
'';
checkPhase = ''
# Disable cross compilation tests
export CFG_DISABLE_CROSS_TESTS=1
cargo test
'';
# Disable check phase as there are failures (4 tests fail)
doCheck = false;
meta = with lib; {
homepage = https://crates.io;
description = "Downloads your Rust project's dependencies and builds your project";
maintainers = with maintainers; [ retrry ];
license = [ licenses.mit licenses.asl20 ];
platforms = platforms.unix;
};
}

View file

@ -1,35 +0,0 @@
{ stdenv, lib, rustPlatform, rustc, Security, patchelf }:
rustPlatform.buildRustPackage {
name = "clippy-${rustc.version}";
inherit (rustc) version src;
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
cargoVendorDir = "vendor";
preBuild = "pushd src/tools/clippy";
postBuild = "popd";
# changes hash of vendor directory otherwise
dontUpdateAutotoolsGnuConfigScripts = true;
buildInputs = [ rustc rustc.llvm ] ++ lib.optionals stdenv.isDarwin [ Security ];
# fixes: error: the option `Z` is only accepted on the nightly compiler
RUSTC_BOOTSTRAP = 1;
# Without disabling the test the build fails with:
# error: failed to run custom build command for `rustc_llvm v0.0.0
# (/private/tmp/nix-build-clippy-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm)
doCheck = false;
preFixup = lib.optionalString stdenv.isDarwin ''
install_name_tool -add_rpath "${rustc}/lib" $out/bin/clippy-driver
'';
meta = with lib; {
homepage = "https://rust-lang.github.io/rust-clippy/";
description = "A bunch of lints to catch common mistakes and improve your Rust code";
maintainers = with maintainers; [ basvandijk ];
license = with licenses; [ mit asl20 ];
platforms = platforms.unix;
};
}

View file

@ -1,98 +0,0 @@
{ rustcVersion
, rustcSha256
, enableRustcDev ? true
, bootstrapVersion
, bootstrapHashes
, selectRustPackage
}:
{ stdenv, lib
, buildPackages
, newScope, callPackage
, CoreFoundation, Security
, llvmPackages_5
, pkgsBuildTarget, pkgsBuildBuild
, path # [naersk]: needed to get the nixpkgs source
}: rec {
toRustTarget = platform: with platform.parsed; let
cpu_ = {
"armv7a" = "armv7";
"armv7l" = "armv7";
"armv6l" = "arm";
}.${cpu.name} or platform.rustc.arch or cpu.name;
in platform.rustc.config
or "${cpu_}-${vendor.name}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}";
makeRustPlatform = { rustc, cargo, ... }: rec {
rust = {
inherit rustc cargo;
};
fetchcargo = buildPackages.callPackage (path + /pkgs/build-support/rust/fetchcargo.nix) {
inherit cargo;
};
buildRustPackage = callPackage (path + /pkgs/build-support/rust) {
inherit rustc cargo fetchcargo;
};
rustcSrc = callPackage ./rust-src.nix {
inherit rustc;
};
};
# This just contains tools for now. But it would conceivably contain
# libraries too, say if we picked some default/recommended versions from
# `cratesIO` to build by Hydra and/or try to prefer/bias in Cargo.lock for
# all vendored Carnix-generated nix.
#
# In the end game, rustc, the rust standard library (`core`, `std`, etc.),
# and cargo would themselves be built with `buildRustCreate` like
# everything else. Tools and `build.rs` and procedural macro dependencies
# would be taken from `buildRustPackages` (and `bootstrapRustPackages` for
# anything provided prebuilt or their build-time dependencies to break
# cycles / purify builds). In this way, nixpkgs would be in control of all
# bootstrapping.
packages = {
prebuilt = callPackage ./bootstrap.nix {
version = bootstrapVersion;
hashes = bootstrapHashes;
};
stable = lib.makeScope newScope (self: let
# Like `buildRustPackages`, but may also contain prebuilt binaries to
# break cycle. Just like `bootstrapTools` for nixpkgs as a whole,
# nothing in the final package set should refer to this.
bootstrapRustPackages = self.buildRustPackages.overrideScope' (_: _:
lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform)
(selectRustPackage buildPackages).packages.prebuilt);
bootRustPlatform = makeRustPlatform bootstrapRustPackages;
in {
# Packages suitable for build-time, e.g. `build.rs`-type stuff.
buildRustPackages = (selectRustPackage buildPackages).packages.stable;
# Analogous to stdenv
rustPlatform = makeRustPlatform self.buildRustPackages;
rustc = self.callPackage ./rustc.nix ({
version = rustcVersion;
sha256 = rustcSha256;
inherit enableRustcDev;
# Use boot package set to break cycle
rustPlatform = bootRustPlatform;
} // lib.optionalAttrs (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) {
stdenv = llvmPackages_5.stdenv;
/* [naersk]: we don't need this, it's too complicated
pkgsBuildBuild = pkgsBuildBuild // { targetPackages.stdenv = llvmPackages_5.stdenv; };
pkgsBuildHost = pkgsBuildBuild // { targetPackages.stdenv = llvmPackages_5.stdenv; };
pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmPackages_5.stdenv; };
*/
});
rustfmt = self.callPackage ./rustfmt.nix { inherit Security; };
cargo = self.callPackage ./cargo.nix {
# Use boot package set to break cycle
rustPlatform = bootRustPlatform;
inherit CoreFoundation Security;
};
clippy = self.callPackage ./clippy.nix { inherit Security; };
rls = self.callPackage ./rls { inherit CoreFoundation Security; };
});
};
}

View file

@ -1,23 +0,0 @@
# [naersk] this is needed for proper musl builds
# We need libunwind-9.0.0 because earlier versions link c++ symbols we don't
# have to have to link to
{ fetchurl, stdenv, lib, cmake, enableShared ? true }:
let
version = "9.0.0";
fetch = sha256: fetchurl {
url = "https://releases.llvm.org/${version}/libunwind-${version}.src.tar.xz";
inherit sha256;
};
in
stdenv.mkDerivation rec {
pname = "libunwind";
inherit version;
src = fetch "1chd1nz4bscrs6qa7p8sqgk5df86ll0frv0f451vhks2w44qsslp";
nativeBuildInputs = [ cmake ];
enableParallelBuilding = true;
cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
}

View file

@ -1,39 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
# All rust-related downloads can be found at
# https://static.rust-lang.org/dist/index.html. To find the date on
# which a particular thing was last updated, look for the *-date.txt
# file, e.g.
# https://static.rust-lang.org/dist/channel-rust-beta-date.txt
PLATFORMS=(
i686-unknown-linux-gnu
x86_64-unknown-linux-gnu
arm-unknown-linux-gnueabihf
armv7-unknown-linux-gnueabihf
aarch64-unknown-linux-gnu
i686-apple-darwin
x86_64-apple-darwin
)
BASEURL=https://static.rust-lang.org/dist
VERSION=${1:-}
DATE=${2:-}
if [[ -z $VERSION ]]
then
echo "No version supplied"
exit -1
fi
if [[ -n $DATE ]]
then
BASEURL=$BASEURL/$DATE
fi
for PLATFORM in "${PLATFORMS[@]}"
do
URL="$BASEURL/rust-$VERSION-$PLATFORM.tar.gz.sha256"
SHA256=$(curl -sSfL $URL | cut -d ' ' -f 1)
echo "$PLATFORM = \"$SHA256\";"
done

View file

@ -1,45 +0,0 @@
{ stdenv, lib, fetchFromGitHub, rustPlatform
, openssh, openssl, pkg-config, cmake, zlib, curl, libiconv
, CoreFoundation, Security }:
rustPlatform.buildRustPackage {
pname = "rls";
inherit (rustPlatform.rust.rustc) src version;
# changes hash of vendor directory otherwise
dontUpdateAutotoolsGnuConfigScripts = true;
cargoVendorDir = "vendor";
preBuild = ''
pushd src/tools/rls
# client tests are flaky
rm tests/client.rs
'';
# a nightly compiler is required unless we use this cheat code.
RUSTC_BOOTSTRAP=1;
# rls-rustc links to rustc_private crates
CARGO_BUILD_RUSTFLAGS = if stdenv.isDarwin then "-C rpath" else null;
nativeBuildInputs = [ pkg-config cmake ];
buildInputs = [ openssh openssl curl zlib libiconv rustPlatform.rust.rustc.llvm ]
++ (lib.optionals stdenv.isDarwin [ CoreFoundation Security ]);
doCheck = true;
preInstall = "popd";
doInstallCheck = true;
installCheckPhase = ''
$out/bin/rls --version
'';
meta = with lib; {
description = "Rust Language Server - provides information about Rust programs to IDEs and other tools";
homepage = "https://github.com/rust-lang/rls/";
license = with licenses; [ asl20 /* or */ mit ];
maintainers = with maintainers; [ symphorien ];
platforms = platforms.all;
};
}

View file

@ -1,11 +0,0 @@
{ stdenv, rustc }:
stdenv.mkDerivation {
name = "rust-src";
src = rustc.src;
phases = [ "unpackPhase" "installPhase" ];
installPhase = ''
mv src $out
rm -rf $out/{ci,doc,etc,grammar,llvm-project,llvm-emscripten,rtstartup,rustllvm,test,tools,vendor,stdarch}
'';
}

View file

@ -1,259 +0,0 @@
{ stdenv, removeReferencesTo, pkgsBuildBuild, pkgsBuildHost, pkgsBuildTarget
, lib
, fetchurl, file, python3
, llvm_9, darwin, git, cmake, rust, rustPlatform
, pkg-config, openssl
, which, libffi
, withBundledLLVM ? false
, enableRustcDev ? true
, version
, sha256
, patches ? []
# [naersk]: extra inputs for musl
, pkgsStatic
, pkgs
, runCommand
, musl
, makeWrapper
}:
# [naersk] We make some assumptions about the platform below, this is just a
# sanity check
assert
if stdenv.isLinux then
stdenv.buildPlatform.config == "x86_64-unknown-linux-gnu"
else
stdenv.buildPlatform.config == "x86_64-apple-darwin"
;
let
# [naersk]: hard code two targets (musl (on Linux) + wasm32)
targets =
[
"${rust.toRustTarget stdenv.buildPlatform}"
"wasm32-unknown-unknown"
]
# on Linux we also build the musl target for fully static executables
++ lib.optionals stdenv.isLinux [ "x86_64-unknown-linux-musl" ]
;
host = stdenv.buildPlatform.config;
inherit (lib) optionals optional optionalString;
inherit (darwin.apple_sdk.frameworks) Security;
/* [naersk]: no need for this
llvmSharedForBuild = pkgsBuildBuild.llvm_9.override { enableSharedLibraries = true; };
llvmSharedForHost = pkgsBuildHost.llvm_9.override { enableSharedLibraries = true; };
llvmSharedForTarget = pkgsBuildTarget.llvm_9.override { enableSharedLibraries = true; };
*/
# For use at runtime
llvmShared = llvm_9.override { enableSharedLibraries = true; };
in stdenv.mkDerivation rec {
pname = "rustc";
inherit version;
src = fetchurl {
url = "https://static.rust-lang.org/dist/rustc-${version}-src.tar.gz";
inherit sha256;
};
__darwinAllowLocalNetworking = true;
# rustc complains about modified source files otherwise
dontUpdateAutotoolsGnuConfigScripts = true;
# Running the default `strip -S` command on Darwin corrupts the
# .rlib files in "lib/".
#
# See https://github.com/NixOS/nixpkgs/pull/34227
#
# Running `strip -S` when cross compiling can harm the cross rlibs.
# See: https://github.com/NixOS/nixpkgs/pull/56540#issuecomment-471624656
stripDebugList = [ "bin" ];
NIX_LDFLAGS = toString (
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch'
optional (stdenv.isLinux && !withBundledLLVM) "--push-state --as-needed -lstdc++ --pop-state"
++ optional (stdenv.isDarwin && !withBundledLLVM) "-lc++"
++ optional stdenv.isDarwin "-rpath ${llvmShared}/lib");
# Increase codegen units to introduce parallelism within the compiler.
RUSTFLAGS = "-Ccodegen-units=10";
# We need rust to build rust. If we don't provide it, configure will try to download it.
# Reference: https://github.com/rust-lang/rust/blob/master/src/bootstrap/configure.py
configureFlags = let
# [naersk]: a bunch of stuff tweaked for the musl target
# [naersk]: glibc cc
ccForBuild = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
cxxForBuild = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++";
# [naersk]: musl-enabled cc
ccMusl = "${pkgsStatic.stdenv.cc}/bin/${pkgsStatic.stdenv.cc.targetPrefix}cc";
cxxMusl = "${pkgsStatic.stdenv.cc}/bin/${pkgsStatic.stdenv.cc.targetPrefix}c++";
muslRoot =
# the musl-root requires a libunwind.a, so we provide one from llvm
let libunwind = pkgsStatic.callPackage ./libunwind.nix
{ enableShared = false; };
in
runCommand "musl-root" {}
''
mkdir -p $out
cp -r ${musl}/* $out
chmod +w $out/lib
cp ${libunwind}/lib/libunwind.a $out/lib/libunwind.a
'';
/* [naersk]: this is too complicated
setBuild = "--set=target.${rust.toRustTarget stdenv.buildPlatform}";
setHost = "--set=target.${rust.toRustTarget stdenv.hostPlatform}";
setTarget = "--set=target.${rust.toRustTarget stdenv.targetPlatform}";
ccForBuild = "${pkgsBuildBuild.targetPackages.stdenv.cc}/bin/${pkgsBuildBuild.targetPackages.stdenv.cc.targetPrefix}cc";
cxxForBuild = "${pkgsBuildBuild.targetPackages.stdenv.cc}/bin/${pkgsBuildBuild.targetPackages.stdenv.cc.targetPrefix}c++";
ccForHost = "${pkgsBuildHost.targetPackages.stdenv.cc}/bin/${pkgsBuildHost.targetPackages.stdenv.cc.targetPrefix}cc";
cxxForHost = "${pkgsBuildHost.targetPackages.stdenv.cc}/bin/${pkgsBuildHost.targetPackages.stdenv.cc.targetPrefix}c++";
ccForTarget = "${pkgsBuildTarget.targetPackages.stdenv.cc}/bin/${pkgsBuildTarget.targetPackages.stdenv.cc.targetPrefix}cc";
cxxForTarget = "${pkgsBuildTarget.targetPackages.stdenv.cc}/bin/${pkgsBuildTarget.targetPackages.stdenv.cc.targetPrefix}c++";
*/
in [
"--release-channel=stable"
"--set=build.rustc=${rustPlatform.rust.rustc}/bin/rustc"
"--set=build.cargo=${rustPlatform.rust.cargo}/bin/cargo"
"--enable-rpath"
"--enable-vendor"
"--build=${rust.toRustTarget stdenv.buildPlatform}"
"--host=${rust.toRustTarget stdenv.hostPlatform}"
/* [naersk]: some more pkgsCross complications
"--enable-llvm-link-shared"
"--set=target.${stdenv.buildPlatform.config}.llvm-config=${llvmShared}/bin/llvm-config"
] ++ lib.optionals stdenv.isLinux
[
"--set=target.x86_64-unknown-linux-gnu.cc=${ccForBuild}"
"--set=target.x86_64-unknown-linux-gnu.linker=${ccForBuild}"
"--set=target.x86_64-unknown-linux-gnu.cxx=${cxxForBuild}"
"--set=target.x86_64-unknown-linux-musl.cc=${ccMusl}"
"--set=target.x86_64-unknown-linux-musl.linker=${ccMusl}"
"--set=target.x86_64-unknown-linux-musl.cxx=${cxxMusl}"
"--set=target.x86_64-unknown-linux-musl.musl-root=${muslRoot}"
*/
# [naersk]: we replace those with ours
"--enable-llvm-link-shared"
"--set=target.${stdenv.buildPlatform.config}.llvm-config=${llvmShared}/bin/llvm-config"
] ++ lib.optionals stdenv.isLinux
[
"--set=target.x86_64-unknown-linux-gnu.cc=${ccForBuild}"
"--set=target.x86_64-unknown-linux-gnu.linker=${ccForBuild}"
"--set=target.x86_64-unknown-linux-gnu.cxx=${cxxForBuild}"
"--set=target.x86_64-unknown-linux-musl.cc=${ccMusl}"
"--set=target.x86_64-unknown-linux-musl.linker=${ccMusl}"
"--set=target.x86_64-unknown-linux-musl.cxx=${cxxMusl}"
"--set=target.x86_64-unknown-linux-musl.musl-root=${muslRoot}"
/* [naersk]: we got extra targets, so we replace with our own
"--target=${rust.toRustTarget stdenv.targetPlatform}"
*/ "--target=${lib.concatStringsSep "," targets}"
/* [naersk]: extra nixpkgs complicated stuff
"${setBuild}.cc=${ccForBuild}"
"${setHost}.cc=${ccForHost}"
"${setTarget}.cc=${ccForTarget}"
"${setBuild}.linker=${ccForBuild}"
"${setHost}.linker=${ccForHost}"
"${setTarget}.linker=${ccForTarget}"
"${setBuild}.cxx=${cxxForBuild}"
"${setHost}.cxx=${cxxForHost}"
"${setTarget}.cxx=${cxxForTarget}"
] ++ optionals (!withBundledLLVM) [
"--enable-llvm-link-shared"
"${setBuild}.llvm-config=${llvmSharedForBuild}/bin/llvm-config"
"${setHost}.llvm-config=${llvmSharedForHost}/bin/llvm-config"
"${setTarget}.llvm-config=${llvmSharedForTarget}/bin/llvm-config"
] ++ optionals stdenv.isLinux [
*/
"--enable-profiler" # build libprofiler_builtins
] ++ lib.optionals stdenv.isDarwin # [naersk]: let's not forget about darwin
[
"--set=target.x86_64-apple-darwin.cc=${ccForBuild}"
"--set=target.x86_64-apple-darwin.linker=${ccForBuild}"
"--set=target.x86_64-apple-darwin.cxx=${cxxForBuild}"
];
# The bootstrap.py will generated a Makefile that then executes the build.
# The BOOTSTRAP_ARGS used by this Makefile must include all flags to pass
# to the bootstrap builder.
postConfigure = ''
substituteInPlace Makefile \
--replace 'BOOTSTRAP_ARGS :=' 'BOOTSTRAP_ARGS := --jobs $(NIX_BUILD_CORES)'
'';
# the rust build system complains that nix alters the checksums
dontFixLibtool = true;
postPatch = ''
patchShebangs src/etc
${optionalString (!withBundledLLVM) ''rm -rf src/llvm''}
# Fix the configure script to not require curl as we won't use it
sed -i configure \
-e '/probe_need CFG_CURL curl/d'
# Useful debugging parameter
# export VERBOSE=1
'';
# rustc unfortunately needs cmake to compile llvm-rt but doesn't
# use it for the normal build. This disables cmake in Nix.
dontUseCmakeConfigure = true;
nativeBuildInputs = [
file python3 rustPlatform.rust.rustc git cmake
which libffi removeReferencesTo pkg-config
];
buildInputs = [ openssl ]
++ optional stdenv.isDarwin Security
++ optional (!withBundledLLVM) llvmShared;
outputs = [ "out" "man" "doc" ];
setOutputFlags = false;
postInstall = lib.optionalString enableRustcDev ''
# install rustc-dev components. Necessary to build rls, clippy...
python x.py dist rustc-dev
tar xf build/dist/rustc-dev*tar.gz
cp -r rustc-dev*/rustc-dev*/lib/* $out/lib/
'' + ''
# remove references to llvm-config in lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_codegen_llvm-llvm.so
# and thus a transitive dependency on ncurses
find $out/lib -name "*.so" -type f -exec remove-references-to -t ${llvmShared} '{}' '+'
'';
configurePlatforms = [];
# https://github.com/NixOS/nixpkgs/pull/21742#issuecomment-272305764
# https://github.com/rust-lang/rust/issues/30181
# enableParallelBuilding = false;
setupHooks = ./setup-hook.sh;
requiredSystemFeatures = [ "big-parallel" ];
passthru.llvm = llvmShared;
meta = with lib; {
homepage = "https://www.rust-lang.org/";
description = "A safe, concurrent, practical language";
maintainers = with maintainers; [ madjar cstrahan globin havvy ];
license = [ licenses.mit licenses.asl20 ];
platforms = platforms.linux ++ platforms.darwin;
};
}

View file

@ -1,33 +0,0 @@
{ stdenv, lib, rustPlatform, Security }:
rustPlatform.buildRustPackage rec {
pname = "rustfmt";
inherit (rustPlatform.rust.rustc) version src;
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
cargoVendorDir = "vendor";
preBuild = "pushd src/tools/rustfmt";
preInstall = "popd";
# changes hash of vendor directory otherwise
dontUpdateAutotoolsGnuConfigScripts = true;
buildInputs = lib.optional stdenv.isDarwin Security;
# As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler
RUSTC_BOOTSTRAP = 1;
# we run tests in debug mode so tests look for a debug build of
# rustfmt. Anyway this adds nearly no compilation time.
preCheck = ''
cargo build
'';
meta = with lib; {
description = "A tool for formatting Rust code according to style guidelines";
homepage = https://github.com/rust-lang-nursery/rustfmt;
license = with licenses; [ mit asl20 ];
maintainers = with maintainers; [ globin basvandijk ];
platforms = platforms.all;
};
}

View file

@ -1,4 +0,0 @@
# Fix 'failed to open: /homeless-shelter/.cargo/.package-cache' in rust 1.36.
if [[ -z ${IN_NIX_SHELL-} && -z ${CARGO_HOME-} ]]; then
export CARGO_HOME=$TMPDIR
fi

320
test.nix
View file

@ -1,317 +1,5 @@
{ system ? builtins.currentSystem
, fast ? false
, nixpkgs ? "nixpkgs"
}:
let
sources = import ./nix/sources.nix;
pkgs = import ./nix { inherit system nixpkgs; };
naersk = pkgs.callPackage ./default.nix
{ inherit (pkgs.rustPackages) cargo rustc; };
{ system ? builtins.currentSystem, fast ? false, nixpkgs ? "nixpkgs" }:
# very temporary musl tests, just to make sure 1_41_0 builds on 20.03
# (okay, it's actually a wasm test)
muslTests =
{
wasm_rust_1_41_0 =
let
pkgs' = pkgs.appendOverlays
[
(
self: super: rec {
rust_1_41_0 = (
self.callPackage ./rust/1_41_0.nix {
inherit (self.darwin.apple_sdk.frameworks) CoreFoundation Security;
inherit (self) path;
}
);
rust = rust_1_41_0;
rustPackages = self.rust.packages.stable;
inherit (self.rustPackages) rustPlatform;
}
)
];
naersk' = pkgs'.callPackage ./default.nix {};
in
naersk'.buildPackage
{
src = ./test/simple-dep;
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "${pkgs'.llvmPackages_9.lld}/bin/lld";
};
musl_rust_1_41_0 =
let
pkgs' = pkgs.appendOverlays
[
(
self: super: rec {
rust_1_41_0 = (
self.callPackage ./rust/1_41_0.nix {
inherit (self.darwin.apple_sdk.frameworks) CoreFoundation Security;
inherit (self) path;
}
);
rust = rust_1_41_0;
rustPackages = self.rust.packages.stable;
inherit (self.rustPackages) rustPlatform;
}
)
];
naersk' = pkgs'.callPackage ./default.nix {};
in
naersk'.buildPackage
{
src = ./test/simple-dep;
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
};
};
# local tests, that run pretty fast
fastTests =
rec
{
readme = pkgs.runCommand "readme-gen" {}
''
cat ${./README.tpl.md} > $out
${docparse}/bin/docparse ${./config.nix} >> gen
sed -e '/GEN_CONFIGURATION/{r gen' -e 'd}' -i $out
'';
docparse = naersk.buildPackage {
root = ./docparse;
src = builtins.filterSource (
p: t:
let
p' = pkgs.lib.removePrefix (toString ./docparse + "/") p;
in
p' == "Cargo.lock" || p' == "Cargo.toml" || p' == "src" || p' == "src/main.rs"
) ./docparse;
};
readme_test = pkgs.runCommand "readme-test" {}
''
diff ${./README.md} ${readme}
touch $out
'';
# Tests that the builtDependencies derivation can successfully be unpacked
# and that it actually contains cargo's output artifacts. If the result is
# ever empty, cargo will still succeed in building the top level crate, except
# it will need to rebuild all dependencies from scratch, which is wasteful.
# See https://github.com/nix-community/naersk/issues/202
depsTargetNotEmpty = pkgs.runCommand "depsTargetNotEmpty"
{ inherit (simple-dep) builtDependencies; }
''
for dep in $builtDependencies; do
# Make destination directory for unarchiving
mkdir dst
${pkgs.zstd}/bin/zstd -d "$dep/target.tar.zst" --stdout | tar -x -C ./dst
if [ -z "$(ls -A ./dst)" ]; then
echo target directory is empty: "$dep"
return 1
fi
rm -rf ./dst
done
# Success
touch $out
'';
# Same as the test above except checks when the builtDependencies
# derivation is not compressed.
depsUncompressedTargetNotEmpty = pkgs.runCommand "depsUncompressedTargetNotEmpty"
{ inherit (simple-dep-no-compress) builtDependencies; }
''
for dep in $builtDependencies; do
if [ -z "$(ls -A "$dep"/target)" ]; then
echo target directory is empty: "$dep"
return 1
fi
done
# Success
touch $out
'';
simple-dep = naersk.buildPackage {
src = ./test/simple-dep;
doCheck = true;
};
simple-dep-no-compress = naersk.buildPackage {
src = ./test/simple-dep;
doCheck = true;
compressTarget = false;
};
simple-dep-doc = naersk.buildPackage
{
src = ./test/simple-dep;
doDoc = true;
doCheck = true;
};
simple-dep-patched = naersk.buildPackage {
src = ./test/simple-dep-patched;
doCheck = true;
};
dummyfication = naersk.buildPackage {
src = ./test/dummyfication;
doCheck = true;
};
dummyfication_test = pkgs.runCommand
"dummyfication-test"
{ buildInputs = [ dummyfication ]; }
"my-bin > $out";
git-dep = naersk.buildPackage {
doCheck = true;
src = ./test/git-dep;
};
git-dep-by-branch = naersk.buildPackage {
doCheck = true;
src = ./test/git-dep-by-branch;
cargoOptions = (opts: opts ++ [ "--locked" ]);
};
git-dep-by-branch-with-slash =
let
dep = pkgs.runCommand "dep" {
buildInputs = [ pkgs.git ];
} ''
mkdir $out
cd $out
cp -ar ${./test/git-dep-by-branch-with-slash/dep}/* .
git init --initial-branch=with/slash
git add .
git config user.email 'someone'
git config user.name 'someone'
git commit -am 'Initial commit'
'';
app = pkgs.runCommand "app" {
buildInputs = [ pkgs.git ];
} ''
mkdir $out
cd $out
cp -ar ${./test/git-dep-by-branch-with-slash/app}/* .
depPath="${dep}"
depRev=$(cd ${dep} && git rev-parse HEAD)
sed "s:\$depPath:$depPath:" -is Cargo.*
sed "s:\$depRev:$depRev:" -is Cargo.*
'';
in
naersk.buildPackage {
doCheck = true;
src = app;
cargoOptions = (opts: opts ++ [ "--locked" ]);
};
git-dep-by-tag = naersk.buildPackage {
doCheck = true;
src = ./test/git-dep-by-tag;
cargoOptions = (opts: opts ++ [ "--locked" ]);
};
git-dep-dup = naersk.buildPackage {
doCheck = true;
src = ./test/git-dep-dup;
cargoOptions = (opts: opts ++ [ "--locked" ]);
};
cargo-wildcard = naersk.buildPackage {
src = ./test/cargo-wildcard;
doCheck = true;
};
workspace = naersk.buildPackage {
src = ./test/workspace;
doCheck = true;
};
workspace-patched = naersk.buildPackage {
src = ./test/workspace-patched;
doCheck = true;
};
workspace-doc = naersk.buildPackage
{
src = ./test/workspace;
doDoc = true;
doCheck = true;
};
workspace-build-rs = naersk.buildPackage {
src = ./test/workspace-build-rs;
doCheck = true;
};
default-run = naersk.buildPackage {
src = ./test/default-run;
doCheck = true;
};
};
# extra crates, that are kinda slow to build
heavyTests = rec {
ripgrep-all = naersk.buildPackage
{
src = sources.ripgrep-all;
doCheck = true;
};
ripgrep-all_test = pkgs.runCommand "ripgrep-all-test"
{ buildInputs = [ ripgrep-all ]; }
"rga --help && touch $out";
lorri = naersk.buildPackage {
src = sources.lorri;
BUILD_REV_COUNT = 1;
RUN_TIME_CLOSURE = "${sources.lorri}/nix/runtime.nix";
};
lorri_test = pkgs.runCommand "lorri-test" { buildInputs = [ lorri ]; }
"lorri --help && touch $out";
talent-plan-1 = naersk.buildPackage {
src = "${sources.talent-plan}/rust/projects/project-1";
doCheck = true;
};
talent-plan-2 = naersk.buildPackage {
doCheck = true;
src = "${sources.talent-plan}/rust/projects/project-2";
};
talent-plan-3 = naersk.buildPackage "${sources.talent-plan}/rust/projects/project-3";
rustlings = naersk.buildPackage sources.rustlings;
agent-rs = naersk.buildPackage {
doCheck = true;
src = sources.agent-rs;
buildInputs =
[
pkgs.openssl
pkgs.pkg-config
pkgs.perl
] ++ pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.libiconv;
};
};
in
fastTests
// pkgs.lib.optionalAttrs (! fast) heavyTests
// pkgs.lib.optionalAttrs (nixpkgs == "nixpkgs-20.03" && pkgs.stdenv.isLinux) muslTests
import ./test {
inherit system fast nixpkgs;
}

27
test/README.md Normal file
View file

@ -0,0 +1,27 @@
# Tests
This directory contains a handful of naersk's tests; you can run them locally
with:
```
# First, you have to be in the naersk's top-level directory:
$ cd ..
# Then:
$ ./script/test
```
# Caveats
## Dynamically-built Git repositories
Some tests (their READMEs will tell you which ones) utilize dynamically-built
Git repositories (i.e. repositories built _ad hoc_ during the testing through
`pkgs.runCommand`).
Those tests' `Cargo.toml` and `Cargo.lock` contain variables (e.g. `$depPath`,
`$depRev` etc.) that are substituted through our Nix code before the test is
run.
Because of that, it's not possible to execute those tests via `cargo test` (for
whatever the reason you'd like to).

31
test/default.nix Normal file
View file

@ -0,0 +1,31 @@
{ system, fast, nixpkgs }:
let
sources = import ../nix/sources.nix;
pkgs = import ../nix {
inherit system nixpkgs;
};
naersk = pkgs.callPackage ../default.nix {
inherit (pkgs.rustPackages) cargo rustc;
};
args = {
inherit sources pkgs naersk;
};
fastTests = import ./fast args;
slowTests = import ./slow args;
# Because `nix-build` doesn't recurse into attribute sets, some of our more
# nested tests (e.g. `fastTests.foo.bar`) normally wouldn't be executed.
#
# To avoid that, we're recursively flattening all tests into a list, which
# `nix-build` then evaluates in its entirety.
runTests = tests:
pkgs.lib.collect pkgs.lib.isDerivation tests;
in
runTests (
fastTests // pkgs.lib.optionalAttrs (!fast) slowTests
)

View file

@ -0,0 +1,6 @@
{ naersk, ... }:
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
}

View file

@ -0,0 +1,6 @@
{ naersk, ... }:
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
}

16
test/fast/default.nix Normal file
View file

@ -0,0 +1,16 @@
args: {
cargo-wildcard = import ./cargo-wildcard args;
default-run = import ./default-run args;
dummyfication = import ./dummyfication args;
git-dep = import ./git-dep args;
git-dep-by-branch = import ./git-dep-by-branch args;
git-dep-by-branch-with-slash = import ./git-dep-by-branch-with-slash args;
git-dep-by-tag = import ./git-dep-by-tag args;
git-dep-dup = import ./git-dep-dup args;
readme = import ./readme args;
simple-dep = import ./simple-dep args;
simple-dep-patched = import ./simple-dep-patched args;
workspace = import ./workspace args;
workspace-build-rs = import ./workspace-build-rs args;
workspace-patched = import ./workspace-patched args;
}

View file

@ -0,0 +1,11 @@
{ naersk, pkgs, ... }:
let
app = naersk.buildPackage {
src = ./fixtures;
doCheck = true;
};
in
pkgs.runCommand "dummyfication-test" {
buildInputs = [ app ];
} "my-bin > $out"

View file

@ -0,0 +1,16 @@
# Test
This test ensures that we correctly handle dependencies with slashes in their
names (as it requires some extra care around unpacking them).
# Setup
In this test, crate `app` depends on crate `dep`, for which our Nix test-runner
dynamically creates a Git repository with a branch called `with/slash`.
Naersk then builds `app`, and if the compilation succeeds, then everything must
be working correctly.
# Caveats
- This test relies on a [dynamically-built Git repository](../../README.md#caveats).

View file

@ -0,0 +1,35 @@
{ naersk, pkgs, ... }:
let
dep = pkgs.runCommand "dep" {
buildInputs = [ pkgs.git ];
} ''
mkdir $out
cd $out
cp -ar ${./fixtures/dep}/* .
git init --initial-branch=with/slash
git add .
git config user.email 'someone'
git config user.name 'someone'
git commit -am 'Initial commit'
'';
app = pkgs.runCommand "app" {
buildInputs = [ pkgs.git ];
} ''
mkdir $out
cd $out
cp -ar ${./fixtures/app}/* .
depPath="${dep}"
depRev=$(cd ${dep} && git rev-parse HEAD)
sed "s:\$depPath:$depPath:" -is Cargo.*
sed "s:\$depRev:$depRev:" -is Cargo.*
'';
in
naersk.buildPackage {
src = app;
doCheck = true;
cargoOptions = (opts: opts ++ [ "--locked" ]);
}

View file

@ -0,0 +1,7 @@
{ naersk, ... }:
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
cargoOptions = (opts: opts ++ [ "--locked" ]);
}

View file

@ -0,0 +1,7 @@
{ naersk, ... }:
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
cargoOptions = (opts: opts ++ [ "--locked" ]);
}

View file

@ -0,0 +1,7 @@
{ naersk, ... }:
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
cargoOptions = (opts: opts ++ [ "--locked" ]);
}

View file

@ -1,4 +1,4 @@
# git-dep-dup
# Test
Same as `git-dep`, but where a git dependency is added multiple times:

View file

@ -0,0 +1,6 @@
{ naersk, ... }:
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
}

View file

@ -0,0 +1,25 @@
{ naersk, pkgs, ... }:
let
docparse = naersk.buildPackage {
root = ../../../docparse;
src = builtins.filterSource (
p: t:
let
p' = pkgs.lib.removePrefix (toString ../../../docparse + "/") p;
in
p' == "Cargo.lock" || p' == "Cargo.toml" || p' == "src" || p' == "src/main.rs"
) ../../../docparse;
};
readme = pkgs.runCommand "readme-gen" {} ''
cat ${../../../README.tpl.md} > $out
${docparse}/bin/docparse ${../../../config.nix} >> gen
sed -e '/GEN_CONFIGURATION/{r gen' -e 'd}' -i $out
'';
in
pkgs.runCommand "readme-test" {} ''
diff ${../../../README.md} ${readme}
touch $out
''

View file

@ -0,0 +1,6 @@
{ naersk, ... }:
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
}

View file

@ -0,0 +1,72 @@
{ naersk, pkgs, ... }: rec {
default = naersk.buildPackage {
src = ./fixtures;
doCheck = true;
};
withCompressTarget = naersk.buildPackage {
src = ./fixtures;
doCheck = true;
compressTarget = true;
};
withoutCompressTarget = naersk.buildPackage {
src = ./fixtures;
doCheck = true;
compressTarget = false;
};
withDoc = naersk.buildPackage {
src = ./fixtures;
doCheck = true;
doDoc = true;
};
withoutDoc = naersk.buildPackage {
src = ./fixtures;
doCheck = true;
doDoc = false;
};
# Tests that the builtDependencies derivation can successfully be unpacked and
# that it actually contains Cargo's output artifacts.
#
# If the result is ever empty, Cargo will still succeed in building the top
# level crate, except it will need to rebuild all dependencies from scratch,
# which is wasteful.
#
# See: https://github.com/nix-community/naersk/issues/202.
depsTargetNotEmptyWhenCompressed = pkgs.runCommand "test" {
inherit (withCompressTarget) builtDependencies;
} ''
for dep in $builtDependencies; do
mkdir dst
${pkgs.zstd}/bin/zstd -d "$dep/target.tar.zst" --stdout | tar -x -C ./dst
if [ -z "$(ls -A ./dst)" ]; then
echo target directory is empty: "$dep"
return 1
fi
rm -rf ./dst
done
# Success
touch $out
'';
# Same as the one above, just for `withoutCompressTarget`
depsTargetNotEmptyWhenNotCompressed = pkgs.runCommand "test" {
inherit (withoutCompressTarget) builtDependencies;
} ''
for dep in $builtDependencies; do
if [ -z "$(ls -A "$dep"/target)" ]; then
echo target directory is empty: "$dep"
return 1
fi
done
# Success
touch $out
'';
}

View file

@ -0,0 +1,6 @@
{ naersk, ... }:
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
}

View file

@ -0,0 +1,6 @@
{ naersk, ... }:
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
}

View file

@ -0,0 +1,12 @@
{ naersk, ... }: {
default = naersk.buildPackage {
src = ./fixtures;
doCheck = true;
};
withDoc = naersk.buildPackage {
src = ./fixtures;
doDoc = true;
doCheck = true;
};
}

View file

@ -1,21 +0,0 @@
# Abstract
This test ensures that we correctly handle dependencies with slashes in their
names (as it requires some extra care around unpacking them).
# Test
`app` depends on `dep`, for which our Nix test-runner dynamically creates a Git
repository with a branch called `with/slash`; naersk then builds `app`, and if
the compilation succeeds, then everything must be working correctly.
For this test to exist, we rely on one trick though:
- Cargo doesn't support relative Git paths (such as `dep = { git = "file:../dep" }`),
but it does support _absolute_ paths - that's why `app`'s `Cargo.toml` and
`Cargo.lock` refer to `dep` via `$depPath` and `$depRev`; those variables are
substituted through Nix code.
A bit unfortunately, that trick also means that this test cannot be run locally
as it is - you'd have to open `app/Cargo.toml` and adjust `$depPath` to be an
actual, absolute path to `dep` on your machine.

Some files were not shown because too many files have changed in this diff Show more