Get a half working example working

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2025-03-03 15:30:17 +01:00
parent dd7142647f
commit 8bff2cf4cc
13 changed files with 595 additions and 17 deletions

View file

@ -0,0 +1,27 @@
{
craneLib,
}:
let
pname = "cargo-dylint-driver";
version = "4.0.0";
src = ../dylint_driver;
commonArgs = {
inherit pname version src;
strictDeps = true;
RUSTUP_TOOLCHAIN = "nightly-nix";
};
in
craneLib.buildPackage (
commonArgs
// {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
doNotRemoveReferencesToRustToolchain = true;
}
)

View file

@ -0,0 +1,82 @@
diff --git a/dylint/build.rs b/dylint/build.rs
index f96b676f..297d2dcf 100644
--- a/dylint/build.rs
+++ b/dylint/build.rs
@@ -31,7 +31,7 @@ fn write_dylint_driver_manifest_dir() {
{
"None".to_owned()
} else {
- let path_buf = dylint_manifest_dir.join("../driver");
+ let path_buf = Path::new("@DRIVER_DIR@");
// smoelius: Ensure the path exists at build time.
assert!(path_buf.is_dir(), "{path_buf:?} is not a directory");
diff --git a/internal/src/cargo.rs b/internal/src/cargo.rs
index 8532d68c..4e7f715c 100644
--- a/internal/src/cargo.rs
+++ b/internal/src/cargo.rs
@@ -14,16 +14,7 @@ use std::{
pub use home::cargo_home;
static STABLE_CARGO: Lazy<PathBuf> = Lazy::new(|| {
- let mut command = Command::new("rustup");
- // smoelius: Rustup 1.27.1 doesn't properly handle the case where the toolchain is specified via
- // both the `RUSTUP_TOOLCHAIN` environment variable and the command line (e.g., `+stable`). This
- // bug is fixed in Rustup's `master` branch, though.
- command.env_remove("RUSTUP_TOOLCHAIN");
- command.args(["+stable", "which", "cargo"]);
- let output = command.logged_output(true).unwrap();
- assert!(output.status.success());
- let stdout = String::from_utf8(output.stdout).unwrap();
- PathBuf::from(stdout.trim_end())
+ PathBuf::from("@STABLE_CARGO@")
});
bitflags! {
diff --git a/internal/src/rustup.rs b/internal/src/rustup.rs
index fb72a3fa..9b320670 100644
--- a/internal/src/rustup.rs
+++ b/internal/src/rustup.rs
@@ -15,7 +15,7 @@ impl SanitizeEnvironment for Command {
fn sanitize_environment(&mut self) -> &mut Self {
self.env_remove(env::CARGO);
self.env_remove(env::RUSTC);
- self.env_remove(env::RUSTUP_TOOLCHAIN);
+ // self.env_remove(env::RUSTUP_TOOLCHAIN);
self
}
}
@@ -23,31 +23,11 @@ impl SanitizeEnvironment for Command {
// smoelius: Consider carefully whether you need to call this function! In most cases, the toolchain
// you want is not the one returned by rustup.
pub fn active_toolchain(path: &Path) -> Result<String> {
- let output = Command::new("rustup")
- .sanitize_environment()
- .current_dir(path)
- .args(["show", "active-toolchain"])
- .logged_output(true)?;
- let stdout = std::str::from_utf8(&output.stdout)?;
- stdout
- .split_once(' ')
- .map(|(s, _)| s.to_owned())
- .ok_or_else(|| anyhow!("Could not determine active toolchain"))
+ Ok(String::from("@RUST_TOOLCHAIN@"))
}
pub fn toolchain_path(path: &Path) -> Result<PathBuf> {
- let output = Command::new("rustup")
- .sanitize_environment()
- .current_dir(path)
- .args(["which", "rustc"])
- .logged_output(true)?;
- let stdout = std::str::from_utf8(&output.stdout)?;
- let path = PathBuf::from(stdout);
- // smoelius: `path` should end with `/bin/rustc`.
- path.ancestors()
- .nth(2)
- .map(Into::into)
- .ok_or_else(|| anyhow!("Could not get ancestor"))
+ Ok(PathBuf::from("@RUST_TOOLCHAIN_PATH@"))
}
pub fn is_rustc<T: AsRef<OsStr> + ?Sized>(arg: &T) -> bool {

View file

@ -4,6 +4,8 @@
pkg-config,
openssl,
cargo-dylint-driver,
}:
let
@ -16,24 +18,44 @@ let
tag = "v${version}";
sha256 = "sha256-Z8uuewp7Buoadayc0oTafmfvwNT36KukWKiHxL/mQfI=";
};
commonArgs = {
inherit pname version src;
buildInputs = [
openssl
];
nativeBuildInputs = [
pkg-config
];
RUSTUP_TOOLCHAIN = "nightly-nix";
doCheck = false;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
craneLib.buildPackage {
inherit
pname
version
src
;
craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
buildInputs = [
openssl
];
patches = [ ./cargo-dylint-patch-rustup.patch ];
nativeBuildInputs = [
pkg-config
];
postPatch = ''
substituteInPlace dylint/build.rs \
--replace-fail @DRIVER_DIR@ ${src}/driver
RUSTUP_TOOLCHAIN = craneLib.rustc.version;
substituteInPlace internal/src/cargo.rs \
--replace-fail @STABLE_CARGO@ ${craneLib.cargo}/bin/cargo
doCheck = false;
}
substituteInPlace internal/src/rustup.rs \
--replace-fail @RUST_TOOLCHAIN@ "nightly-nix" \
--replace-fail @RUST_TOOLCHAIN_PATH@ ${craneLib.rustc}
'';
doNotRemoveReferencesToRustToolchain = true;
}
)

View file

@ -9,6 +9,7 @@ let
callPackage = pkgs.lib.callPackageWith (pkgs // packages // { inherit inputs craneLib; });
packages = {
cargo-dylint = callPackage ./cargo-dylint.nix { };
cargo-dylint-driver = callPackage ./cargo-dylint-driver.nix { };
};
in