Skip to content

Commit a1a82c9

Browse files
authored
Merge pull request #2199 from benwis/main
Patched build.rs to run on systems without rustup. Added flake for ni…
2 parents 8fed943 + 815b231 commit a1a82c9

File tree

4 files changed

+183
-3
lines changed

4 files changed

+183
-3
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake;

build.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,20 @@ fn build_wasm_test_program(name: &'static str, root: &'static str) {
133133
}
134134

135135
fn has_wasm32_wasi_target() -> bool {
136-
let output = run(vec!["rustup", "target", "list", "--installed"], None, None);
137-
let output = std::str::from_utf8(&output.stdout).unwrap();
136+
// Using rustc here for systems that don't have rustup
137+
let output = run(
138+
vec!["rustc", "--print=target-libdir", "--target=wasm32-wasi"],
139+
None,
140+
None,
141+
);
142+
let Ok(output) = std::str::from_utf8(&output.stdout) else {
143+
return false;
144+
};
145+
// If it returns regular output on stdout, then the compiler understands
146+
// If the path exists, then we know the target is installed
147+
// If the path doesn't exist, it must be installed with rustup or something
138148
for line in output.lines() {
139-
if line == "wasm32-wasi" {
149+
if !line.is_empty() && std::path::Path::new(line).exists() {
140150
return true;
141151
}
142152
}

flake.lock

Lines changed: 130 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
{
3+
description = "Nix Devshell for Spin";
4+
5+
inputs = {
6+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
7+
rust-overlay.url = "github:oxalica/rust-overlay";
8+
flake-utils.url = "github:numtide/flake-utils";
9+
};
10+
11+
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
12+
flake-utils.lib.eachDefaultSystem (system:
13+
let
14+
overlays = [ (import rust-overlay) ];
15+
pkgs = import nixpkgs {
16+
inherit system overlays;
17+
};
18+
rustTarget = pkgs.rust-bin.stable.latest.default.override {
19+
extensions= [ "rust-src" "rust-analyzer" ];
20+
targets = [ "wasm32-wasi" "wasm32-unknown-unknown" ];
21+
};
22+
in
23+
with pkgs;
24+
{
25+
devShells.default = mkShell {
26+
buildInputs = [
27+
openssl
28+
pkg-config
29+
rustTarget
30+
];
31+
32+
shellHook = ''
33+
'';
34+
RUST_SRC_PATH = "${rustTarget}/lib/rustlib/src/rust/library";
35+
36+
};
37+
}
38+
);
39+
}

0 commit comments

Comments
 (0)