Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patched build.rs to run on systems without rustup. Added flake for ni… #2199

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";

};
}
);
}