Skip to content

Commit 5008920

Browse files
committed
rustell wasm target works, flake shell small fix
1 parent 305a873 commit 5008920

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

rust/flake.lock

Lines changed: 36 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/flake.nix

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
inputs = {
55
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-25.05";
6+
rust-overlay.url = "github:oxalica/rust-overlay";
67
flake-utils.url = "github:numtide/flake-utils";
78
};
89

910
outputs = {
1011
self,
1112
nixpkgs,
13+
rust-overlay,
1214
flake-utils,
1315
}:
1416
flake-utils.lib.eachDefaultSystem (
@@ -20,6 +22,34 @@
2022
src = pkgs.nix-gitignore.gitignoreSource [] ./${pkg};
2123
cargoLock.lockFile = ./${pkg}/Cargo.lock;
2224
};
25+
mkRustPkgWasm = pkg: let
26+
buildTarget = "wasm32-wasip1";
27+
pkgs = import nixpkgs {
28+
inherit system;
29+
overlays = [rust-overlay.overlays.default];
30+
};
31+
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
32+
targets = [buildTarget];
33+
};
34+
rustPlatform = pkgs.makeRustPlatform {
35+
cargo = rustToolchain;
36+
rustc = rustToolchain;
37+
};
38+
in
39+
rustPlatform.buildRustPackage {
40+
name = pkg;
41+
src = pkgs.nix-gitignore.gitignoreSource [] ./${pkg};
42+
cargoLock.lockFile = ./${pkg}/Cargo.lock;
43+
buildPhase = ''
44+
cargo build --release -p ${pkg} --target=${buildTarget}
45+
'';
46+
installPhase = ''
47+
mkdir -p $out/lib
48+
cp target/${buildTarget}/release/*.wasm $out/lib/
49+
'';
50+
# Disable checks if they only work for WASM
51+
# doCheck = false;
52+
};
2353
in {
2454
devShells.default = pkgs.mkShell {
2555
packages = with pkgs; [
@@ -31,10 +61,15 @@
3161
rust-analyzer
3262
rustc
3363
rustfmt
64+
wasmtime
3465
];
66+
shellHook = ''
67+
SHELL=/run/current-system/sw/bin/bash
68+
'';
3569
};
3670
packages = {
3771
rustell = mkRustPkg "rustell";
72+
rustell-wasm = mkRustPkgWasm "rustell";
3873
default = self.packages.${system}.rustell;
3974
};
4075
}

rust/rustell/src/encode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn expr_use<'a>(
2222
top: bool,
2323
ast: &'a ExprUse<'a>,
2424
) -> IntoIter<&'a str> {
25-
let x0 = if top { vec!["use"] } else { vec![] };
25+
let x0 = if top { vec!["use "] } else { vec![] };
2626

2727
let x1 = match ast {
2828
ExprUse::Item {

0 commit comments

Comments
 (0)