Skip to content

Commit

Permalink
Patched build.rs to run on systems without rustup. Added flake for ni…
Browse files Browse the repository at this point in the history
…x devshell

Signed-off-by: benwis <[email protected]>
  • Loading branch information
benwis committed Dec 21, 2023
1 parent b435f83 commit 5fed5eb
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 = "A basic Rust devshell";

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 5fed5eb

Please sign in to comment.