Skip to content
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

Enable testing this project with a range of Rust toolchain versions #226

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 46 additions & 16 deletions hacking/nix/scope/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,32 @@ let
in

let
fenixRev = "9af557bccdfa8fb6a425661c33dbae46afef0afa";
fenixRev = "dc19afc39af5f5e69fca78ebae59170e61017df8";
fenixSource = fetchTarball "https://github.com/nix-community/fenix/archive/${fenixRev}.tar.gz";
fenix = import fenixSource {};
in

let
elaborateScopeConfig =
{ runClippyDefault ? false
{ rustEnvironmentSelector ? {}
, runClippyDefault ? false
}:
{
let
elaborateRustEnvironmentSelector =
{ tracks ? "upstream"
, upstream ? true
}:
{
inherit
tracks
upstream
;
};
in {
inherit
runClippyDefault
;
rustEnvironmentSelector = elaborateRustEnvironmentSelector rustEnvironmentSelector;
};
in

Expand All @@ -70,17 +83,39 @@ superCallPackage ../rust-utils {} self //

inherit fenix;

topLevelRustToolchainFile = ../../../rust-toolchain.toml;

defaultRustToolchain = fenix.fromToolchainFile {
file = topLevelRustToolchainFile;
sha256 = "sha256-L1F7kAfo8YWrKXHflUaVvCELdvnK2XjcL/lwopFQX2c=";
topLevelRustToolchainFile = rec {
path = ../../../rust-toolchain.toml;
attrs = builtins.fromTOML (builtins.readFile path);
};

upstreamDefaultRustEnvironment = elaborateRustEnvironment (mkDefaultElaborateRustEnvironmentArgs {
rustToolchain = defaultRustToolchain;
assembleRustToolchain = args:
let
toolchain = fenix.toolchainOf args;
profile = topLevelRustToolchainFile.attrs.toolchain.profile or "default";
explicitComponents = topLevelRustToolchainFile.attrs.toolchain.components;
allComponents = toolchain.manifest.profiles.${profile} ++ explicitComponents;
filteredComponents = lib.filter (component: toolchain ? ${component}) allComponents;
in
toolchain.withComponents filteredComponents;

defaultRustEnvironment =
let
inherit (scopeConfig.rustEnvironmentSelector) tracks upstream;
in {
upstream = assert upstream; defaultUpstreamRustEnvironment;
ferrocene = if upstream then ferrocene.upstreamRustEnvironment else ferrocene.rustEnvironment;
verus = assert upstream; verus.rustEnvironment;
}.${tracks};

defaultRustToolchain = defaultRustEnvironment.rustToolchain;

defaultUpstreamRustEnvironment = elaborateRustEnvironment (mkDefaultElaborateRustEnvironmentArgs {
rustToolchain = fenix.fromToolchainFile {
file = topLevelRustToolchainFile.path;
sha256 = "sha256-L1F7kAfo8YWrKXHflUaVvCELdvnK2XjcL/lwopFQX2c=";
};
} // {
channel = (builtins.fromTOML (builtins.readFile topLevelRustToolchainFile)).toolchain.channel;
channel = topLevelRustToolchainFile.attrs.toolchain.channel;
compilerRTSource = mkCompilerRTSource {
version = "19.1-2024-07-30";
hash = "sha256-fV51iDAbkRmWJj0twTmQKdZdLueMAKSZR6bBtgVPCbk=";
Expand All @@ -94,11 +129,6 @@ superCallPackage ../rust-utils {} self //
];
});

ferroceneDefaultRustEnvironment = ferrocene.rustEnvironment;

defaultRustEnvironment = upstreamDefaultRustEnvironment;
# defaultRustEnvironment = ferroceneDefaultRustEnvironment;

mkDefaultElaborateRustEnvironmentArgs = { rustToolchain }: rec {
inherit rustToolchain;

Expand Down
62 changes: 28 additions & 34 deletions hacking/nix/scope/ferrocene/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
, zlib

, fenix
, assembleRustToolchain
, crateUtils
, elaborateRustEnvironment
, mkDefaultElaborateRustEnvironmentArgs
Expand Down Expand Up @@ -166,51 +167,33 @@ let
in

let
# upstreamChannel = "1.79.0";
upstreamChannel = "beta";
# DO NOT CHECK IN THIS FILE
hashesFilePath = ./SHA256SUMS;

# versionTag = "24.08.0";
versionTag = "6ce9c7ddc";
versionName = "pre-rolling-2024-09-11";
upstreamChannel = "1.83.0-beta.2";
upstreamDate = null;

versionTag = builtins.substring 0 9 versionRev;
versionRev = "eecd617bc6f3c693099a1ba900abb93ab9db9196";
versionName = "nightly-2024-10-30";

repo = fetchFromGitHub {
owner = "ferrocene";
repo = "ferrocene";
rev = "6ce9c7ddc767a9b4cddd4ef8a0d4a317bb63159a"; # branch release/1.82
hash = "sha256-r1s3ifDA9QF9dCPieChFjJo9cwEY6vi5RMtXWyUiw0g=";
rev = versionRev;
hash = "sha256-HZBJOESd2O0IGX80YmgjLduO1S8CM7VSQxf85FwJw/8=";
};

libcManifestDir = "${repo}/ferrocene/library/libc";

# DO NOT CHECK IN THIS FILE
hashesFilePath = ./SHA256SUMS;

rustToolchain = mkToolchain {
inherit hashesFilePath;
arch = hostPlatform.config;
inherit versionTag versionName;
inherit libcManifestDir;
};
in

let
upstreamRustToolchain = fenix.fromToolchainFile {
file = crateUtils.toTOMLFile "rust-toolchain.toml" {
toolchain = {
channel = upstreamChannel;
components = [ "rustc-dev" ];
};
};
sha256 = "sha256-4vvAuAhW4cBwR+g1IrI79X7gKL4VsEYKD05XZL0rLc4=";
};

upstreamRustEnvironment = lib.fix (self: elaborateRustEnvironment (mkDefaultElaborateRustEnvironmentArgs {
rustToolchain = upstreamRustToolchain;
} // {
upstreamRustToolchain = assembleRustToolchain ({
channel = upstreamChannel;
}));
sha256 = "sha256-qaGpvEOo1j+3K/YLVFdvVoD6+E3J32U2PmIIb6+FBxw=";
} // lib.optionalAttrs (upstreamDate != null) {
date = upstreamDate;
});

rustEnvironment = lib.fix (self: elaborateRustEnvironment (mkDefaultElaborateRustEnvironmentArgs {
mkRustEnvironment = rustToolchain: lib.fix (self: elaborateRustEnvironment (mkDefaultElaborateRustEnvironmentArgs {
inherit rustToolchain;
} // {
channel = upstreamChannel;
Expand All @@ -219,6 +202,17 @@ let
};
}));

upstreamRustEnvironment = mkRustEnvironment upstreamRustToolchain;

rustToolchain = mkToolchain {
inherit hashesFilePath;
arch = hostPlatform.config;
inherit versionTag versionName;
inherit libcManifestDir;
};

rustEnvironment = mkRustEnvironment rustToolchain;

in {
inherit rustEnvironment;
inherit upstreamRustEnvironment;
Expand Down
11 changes: 3 additions & 8 deletions hacking/nix/scope/verus/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
, crateUtils
, vendorLockfile
, sources
, fenix
, assembleRustToolchain
, elaborateRustEnvironment
, mkDefaultElaborateRustEnvironmentArgs
, mkMkCustomTargetPathForEnvironment
Expand All @@ -23,13 +23,8 @@ let

rustToolchainAttrs = builtins.fromTOML (builtins.readFile (src + "/rust-toolchain.toml"));

rustToolchain = fenix.fromToolchainFile {
file = crateUtils.toTOMLFile "rust-toolchain.toml" (crateUtils.clobber [
rustToolchainAttrs
{
toolchain.components = rustToolchainAttrs.toolchain.components ++ [ "rust-src" ];
}
]);
rustToolchain = assembleRustToolchain {
channel = "1.76.0";
sha256 = "sha256-e4mlaJehWBymYxJGgnbuCObVlqMlQSilZ8FljG9zPHY=";
};

Expand Down
21 changes: 20 additions & 1 deletion hacking/nix/top-level/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,29 @@ in {
})
];

withClippy = self.withConfigOverride (super: super // {
withClippy = self.withConfigOverride (attrs: attrs // {
runClippyDefault = true;
});

withFerrocene = self.withConfigOverride (attrs: attrs // {
rustEnvironmentSelector = (attrs.rustEnvironmentSelector or {}) // {
tracks = "ferrocene";
upstream = false;
};
});

withVerus = self.withConfigOverride (attrs: attrs // {
rustEnvironmentSelector = (attrs.rustEnvironmentSelector or {}) // {
tracks = "verus";
};
});

withUpstream = self.withConfigOverride (attrs: attrs // {
rustEnvironmentSelector = (attrs.rustEnvironmentSelector or {}) // {
upstream = true;
};
});

inherit (pkgs.build.this) shellForMakefile shellForHacking;

worldsForEverythingInstances = [
Expand Down
3 changes: 2 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

[toolchain]
channel = "nightly-2024-10-26"
components = [ "rustfmt", "rust-src", "rustc-dev", "llvm-tools-preview" ]
components = [ "rust-src", "rustc-dev", "llvm-tools-preview" ]
profile = "default"
Loading