From 5fed5ebd9d30f95b4bb3be748dea876c84450223 Mon Sep 17 00:00:00 2001 From: benwis Date: Thu, 21 Dec 2023 08:51:29 -0800 Subject: [PATCH 1/2] Patched build.rs to run on systems without rustup. Added flake for nix devshell Signed-off-by: benwis --- .envrc | 1 + build.rs | 16 +++++-- flake.lock | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 39 ++++++++++++++++ 4 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..44610e56df --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake; diff --git a/build.rs b/build.rs index 007dbd0fe5..a2f0296b5c 100644 --- a/build.rs +++ b/build.rs @@ -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; } } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..e726830e9f --- /dev/null +++ b/flake.lock @@ -0,0 +1,130 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1703013332, + "narHash": "sha256-+tFNwMvlXLbJZXiMHqYq77z/RfmpfpiI3yjL6o/Zo9M=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "54aac082a4d9bb5bbc5c4e899603abfb76a3f6d6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1681358109, + "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1703124916, + "narHash": "sha256-LNAqNYcJf0iCm6jbzhzsQOC4F8SLyma5sckySn2Iffg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "81cb529bd066cd3668f9aa88d2afa8fbbbcd1208", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..9c9b311fef --- /dev/null +++ b/flake.nix @@ -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"; + + }; + } + ); +} From 815b231c650db38ed8737ea3ea82fbf54f103e13 Mon Sep 17 00:00:00 2001 From: benwis Date: Thu, 21 Dec 2023 10:11:29 -0800 Subject: [PATCH 2/2] Edit devshell title Signed-off-by: benwis --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 9c9b311fef..7f0c9a6947 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { - description = "A basic Rust devshell"; + description = "Nix Devshell for Spin"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";