From 5fa2a92dad50aa38b9a5bd769460704550da0d3a Mon Sep 17 00:00:00 2001 From: gram Date: Fri, 24 Oct 2025 13:58:29 +0200 Subject: [PATCH 1/4] Support builds for Moon --- src/commands/new.rs | 5 +++-- src/config.rs | 1 + src/langs.rs | 50 +++++++++++++++++++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/commands/new.rs b/src/commands/new.rs index fb654a8..ad5157f 100644 --- a/src/commands/new.rs +++ b/src/commands/new.rs @@ -25,10 +25,11 @@ pub fn cmd_new(args: &NewArgs) -> Result<()> { Lang::Go => new_go(&args.name).context("new Go project")?, Lang::Rust => new_rust(&args.name).context("new Rust project")?, Lang::Zig => new_zig(&args.name).context("new Zig project")?, - Lang::TS => todo!("TypeScript is not supported yet"), + Lang::TS => bail!("TypeScript is not supported yet"), Lang::C => new_c(&args.name).context("new C project")?, Lang::Cpp => new_cpp(&args.name).context("new C++ project")?, - Lang::Python => todo!("Python is not supported yet"), + Lang::Python => bail!("Python is not supported yet"), + Lang::Moon => bail!("Moon starter project is not supported yet"), } write_config(&args.name)?; init_git(&args.name)?; diff --git a/src/config.rs b/src/config.rs index b8be6ba..fa128dd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -183,4 +183,5 @@ pub enum Lang { C, Cpp, Python, + Moon, } diff --git a/src/langs.rs b/src/langs.rs index 9c11677..6c5050d 100644 --- a/src/langs.rs +++ b/src/langs.rs @@ -28,6 +28,7 @@ pub fn build_bin(config: &Config, args: &BuildArgs) -> anyhow::Result<()> { Lang::C => build_c(config), Lang::Cpp => build_cpp(config), Lang::Python => build_python(config), + Lang::Moon => build_moon(config), }?; let bin_path = config.rom_path.join(BIN); if !bin_path.is_file() { @@ -65,6 +66,9 @@ fn detect_lang(root: &Path) -> anyhow::Result { if root.join("pyproject.toml").exists() { return Ok(Lang::Python); } + if root.join("moon.pkg.json").exists() { + return Ok(Lang::Moon); + } if root.join("main.c").exists() { return Ok(Lang::C); } @@ -308,6 +312,7 @@ fn find_wasi_sdk() -> anyhow::Result { Ok(path) } +// Build Zig project. fn build_zig(config: &Config) -> anyhow::Result<()> { check_installed("Zig", "zig", "version")?; let mut cmd_args = vec!["build"]; @@ -331,6 +336,43 @@ fn build_zig(config: &Config) -> anyhow::Result<()> { Ok(()) } +// Build Moon project. +fn build_moon(config: &Config) -> anyhow::Result<()> { + check_installed("Moon", "moon", "version")?; + let mut cmd_args = vec!["build", "--target", "wasm"]; + if let Some(additional_args) = &config.compile_args { + for arg in additional_args { + cmd_args.push(arg.as_str()); + } + } + let output = Command::new("moon") + .args(cmd_args) + .current_dir(&config.root_path) + .output() + .context("run moon build")?; + check_output(&output)?; + + let from_dir = config + .root_path + .join("target") + .join("wasm") + .join("release") + .join("build"); + let from_path = find_wasm(&from_dir)?; + let out_path = config.rom_path.join(BIN); + std::fs::copy(&from_path, out_path).context("copy wasm binary")?; + std::fs::remove_file(from_path).context("remove wasm file")?; + Ok(()) +} + +fn build_ts(_config: &Config) -> anyhow::Result<()> { + todo!("TypeScript is not supported yet") +} + +fn build_python(_config: &Config) -> anyhow::Result<()> { + todo!("Python is not supported yet") +} + /// Find a wasm binary in the given directory. fn find_wasm(from_dir: &Path) -> anyhow::Result { let from_dir = std::fs::read_dir(from_dir)?; @@ -353,14 +395,6 @@ fn find_wasm(from_dir: &Path) -> anyhow::Result { } } -fn build_ts(_config: &Config) -> anyhow::Result<()> { - todo!("TypeScript is not supported yet") -} - -fn build_python(_config: &Config) -> anyhow::Result<()> { - todo!("Python is not supported yet") -} - /// Convert a file system path to UTF-8 if possible. pub fn path_to_utf8(path: &Path) -> anyhow::Result<&str> { match path.to_str() { From 9c361d5b05c045ea84d52f8a200c8b7046cab30d Mon Sep 17 00:00:00 2001 From: gram Date: Fri, 24 Oct 2025 14:20:32 +0200 Subject: [PATCH 2/4] don't optimize Moon binaries --- src/langs.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/langs.rs b/src/langs.rs index 6c5050d..92e0990 100644 --- a/src/langs.rs +++ b/src/langs.rs @@ -37,7 +37,9 @@ pub fn build_bin(config: &Config, args: &BuildArgs) -> anyhow::Result<()> { if !args.no_strip { strip_custom(&bin_path)?; } - if !args.no_opt { + // TODO(@orsinium): Moon binaries cannot be parsed by wasm-opt, figure out why. + // [parse exception: block cannot pop from outside (at 0:7745)] + if !args.no_opt && !matches!(lang, Lang::Moon) { optimize(&bin_path).context("optimize wasm binary")?; } Ok(()) @@ -69,6 +71,9 @@ fn detect_lang(root: &Path) -> anyhow::Result { if root.join("moon.pkg.json").exists() { return Ok(Lang::Moon); } + if root.join("moon.mod.json").exists() { + return Ok(Lang::Moon); + } if root.join("main.c").exists() { return Ok(Lang::C); } From 785b9bc50d9b7e68ae98b5458fe401e9b40a7b79 Mon Sep 17 00:00:00 2001 From: gram Date: Sun, 26 Oct 2025 19:57:51 +0100 Subject: [PATCH 3/4] do apt update on CI --- .github/workflows/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ac4d048..8dc00ce 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,8 @@ jobs: - uses: arduino/setup-task@v1 with: repo-token: ${{ github.token }} - - run: sudo apt install -qq -y libudev-dev + - run: apt update + - run: apt install -qq -y libudev-dev - run: task test lint: @@ -37,7 +38,8 @@ jobs: - uses: arduino/setup-task@v1 with: repo-token: ${{ github.token }} - - run: sudo apt install -qq -y libudev-dev + - run: apt update + - run: apt install -qq -y libudev-dev - run: task lint markdownlint-cli: From 4b843417e8808395dc5ddd0b395721a8c641d317 Mon Sep 17 00:00:00 2001 From: gram Date: Sun, 26 Oct 2025 19:59:00 +0100 Subject: [PATCH 4/4] call apt with sudo --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8dc00ce..a487220 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,8 +24,8 @@ jobs: - uses: arduino/setup-task@v1 with: repo-token: ${{ github.token }} - - run: apt update - - run: apt install -qq -y libudev-dev + - run: sudo apt update + - run: sudo apt install -qq -y libudev-dev - run: task test lint: @@ -38,8 +38,8 @@ jobs: - uses: arduino/setup-task@v1 with: repo-token: ${{ github.token }} - - run: apt update - - run: apt install -qq -y libudev-dev + - run: sudo apt update + - run: sudo apt install -qq -y libudev-dev - run: task lint markdownlint-cli: