Skip to content

Commit 56fd390

Browse files
committed
Add flake.nix and .envrc
1 parent e2cf31a commit 56fd390

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed

.envrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if nix flake show path:./src/tools/nix-dev-shell &> /dev/null; then
2+
use flake path:./src/tools/nix-dev-shell
3+
fi

src/tools/nix-dev-shell/flake.lock

+61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/nix-dev-shell/flake.nix

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
description = "rustc dev shell";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils, ... }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = import nixpkgs { inherit system; };
13+
x = import ./x { inherit pkgs; };
14+
in
15+
{
16+
devShells.default = with pkgs; mkShell {
17+
name = "rustc-dev-shell";
18+
nativeBuildInputs = with pkgs; [
19+
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
20+
];
21+
buildInputs = with pkgs; [
22+
openssl glibc.out glibc.static x
23+
];
24+
# Avoid creating text files for ICEs.
25+
RUSTC_ICE = "0";
26+
# Provide `libstdc++.so.6` for the self-contained lld.
27+
LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [
28+
stdenv.cc.cc.lib
29+
]}";
30+
};
31+
}
32+
);
33+
}

src/tools/nix-dev-shell/x/default.nix

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
pkgs ? import <nixpkgs> { },
3+
}:
4+
pkgs.stdenv.mkDerivation {
5+
name = "x";
6+
7+
src = ./x.rs;
8+
dontUnpack = true;
9+
10+
nativeBuildInputs = with pkgs; [ rustc ];
11+
12+
buildPhase = ''
13+
PYTHON=${pkgs.lib.getExe pkgs.python3} rustc -Copt-level=3 --crate-name x $src --out-dir $out/bin
14+
'';
15+
16+
meta = with pkgs.lib; {
17+
description = "Helper for rust-lang/rust x.py";
18+
homepage = "https://github.com/rust-lang/rust/blob/master/src/tools/x";
19+
license = licenses.mit;
20+
mainProgram = "x";
21+
};
22+
}

src/tools/nix-dev-shell/x/x.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// git clone https://github.com/rust-lang/rust/blob/0ea7ddcc35a2fcaa5da8a7dcfc118c9fb4a63b95/src/tools/x/src/main.rs
2+
// patched to stop doing python probing, stop the probe, please dont, i have a python
3+
//! Run bootstrap from any subdirectory of a rust compiler checkout.
4+
//!
5+
//! We prefer `exec`, to avoid adding an extra process in the process tree.
6+
//! However, since `exec` isn't available on Windows, we indirect through
7+
//! `exec_or_status`, which will call `exec` on unix and `status` on Windows.
8+
//!
9+
//! We use `powershell.exe x.ps1` on Windows, and `sh -c x` on Unix, those are
10+
//! the ones that call `x.py`. We use `sh -c` on Unix, because it is a standard.
11+
//! We also don't use `pwsh` on Windows, because it is not installed by default;
12+
13+
use std::{
14+
env,
15+
os::unix::process::CommandExt,
16+
process::{self, Command},
17+
};
18+
19+
fn main() {
20+
match env::args().skip(1).next().as_deref() {
21+
Some("--wrapper-version") => {
22+
println!("0.1.0");
23+
return;
24+
}
25+
_ => {}
26+
}
27+
let current = match env::current_dir() {
28+
Ok(dir) => dir,
29+
Err(err) => {
30+
eprintln!("Failed to get current directory: {err}");
31+
process::exit(1);
32+
}
33+
};
34+
35+
for dir in current.ancestors() {
36+
let candidate = dir.join("x.py");
37+
if candidate.exists() {
38+
let mut cmd = Command::new(env!("PYTHON"));
39+
cmd.arg(dir.join("x.py"));
40+
cmd.args(env::args().skip(1)).current_dir(dir);
41+
42+
let error = cmd.exec();
43+
eprintln!("Failed to invoke `{:?}`: {}", cmd, error);
44+
}
45+
}
46+
47+
eprintln!(
48+
"x.py not found. Please run inside of a checkout of `https://github.com/rust-lang/rust`."
49+
);
50+
51+
process::exit(1);
52+
}

0 commit comments

Comments
 (0)