diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ac4d048..a487220 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,6 +24,7 @@ jobs: - uses: arduino/setup-task@v1 with: repo-token: ${{ github.token }} + - run: sudo apt update - run: sudo apt install -qq -y libudev-dev - run: task test @@ -37,6 +38,7 @@ jobs: - uses: arduino/setup-task@v1 with: repo-token: ${{ github.token }} + - run: sudo apt update - run: sudo apt install -qq -y libudev-dev - run: task lint 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..92e0990 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() { @@ -36,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(()) @@ -65,6 +68,12 @@ 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("moon.mod.json").exists() { + return Ok(Lang::Moon); + } if root.join("main.c").exists() { return Ok(Lang::C); } @@ -308,6 +317,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 +341,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 +400,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() {