Skip to content

Commit

Permalink
Merge pull request #2199 from benwis/main
Browse files Browse the repository at this point in the history
Patched build.rs to run on systems without rustup. Added flake for ni…
  • Loading branch information
itowlson authored Dec 21, 2023
2 parents 8fed943 + 815b231 commit a1a82c9
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 3 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake;
16 changes: 13 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,20 @@ fn build_wasm_test_program(name: &'static str, root: &'static str) {
}

fn has_wasm32_wasi_target() -> bool {
let output = run(vec!["rustup", "target", "list", "--installed"], None, None);
let output = std::str::from_utf8(&output.stdout).unwrap();
// Using rustc here for systems that don't have rustup
let output = run(
vec!["rustc", "--print=target-libdir", "--target=wasm32-wasi"],
None,
None,
);
let Ok(output) = std::str::from_utf8(&output.stdout) else {
return false;
};
// If it returns regular output on stdout, then the compiler understands
// If the path exists, then we know the target is installed
// If the path doesn't exist, it must be installed with rustup or something
for line in output.lines() {
if line == "wasm32-wasi" {
if !line.is_empty() && std::path::Path::new(line).exists() {
return true;
}
}
Expand Down
130 changes: 130 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

{
description = "Nix Devshell for Spin";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustTarget = pkgs.rust-bin.stable.latest.default.override {
extensions= [ "rust-src" "rust-analyzer" ];
targets = [ "wasm32-wasi" "wasm32-unknown-unknown" ];
};
in
with pkgs;
{
devShells.default = mkShell {
buildInputs = [
openssl
pkg-config
rustTarget
];

shellHook = ''
'';
RUST_SRC_PATH = "${rustTarget}/lib/rustlib/src/rust/library";

};
}
);
}

0 comments on commit a1a82c9

Please sign in to comment.