Skip to content
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,5 @@ pub enum Lang {
C,
Cpp,
Python,
Moon,
}
57 changes: 48 additions & 9 deletions src/langs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(())
Expand Down Expand Up @@ -65,6 +68,12 @@ fn detect_lang(root: &Path) -> anyhow::Result<Lang> {
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);
}
Expand Down Expand Up @@ -308,6 +317,7 @@ fn find_wasi_sdk() -> anyhow::Result<PathBuf> {
Ok(path)
}

// Build Zig project.
fn build_zig(config: &Config) -> anyhow::Result<()> {
check_installed("Zig", "zig", "version")?;
let mut cmd_args = vec!["build"];
Expand All @@ -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<PathBuf> {
let from_dir = std::fs::read_dir(from_dir)?;
Expand All @@ -353,14 +400,6 @@ fn find_wasm(from_dir: &Path) -> anyhow::Result<PathBuf> {
}
}

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() {
Expand Down