diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 13be1a5..dcbd908 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -2,6 +2,15 @@ name = "compiler_cli" version = "0.1.0" edition = "2024" +default-run = "reggie" + +[[bin]] +name = "reggie" +path = "src/bin/reggie.rs" + +[[bin]] +name = "regulus" +path = "src/bin/regulus.rs" [dependencies] clap = { version = "4.5.40", features = ["derive"] } diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index 73d7ce1..244b5e1 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -4,7 +4,6 @@ use clap::{Parser, Subcommand, ValueEnum}; use compiler_core::target::CompileTarget; #[derive(Debug, Parser)] -#[command(name = "gleam-wasm")] #[command(about = "Compile Gleam source to WebAssembly")] pub struct Args { #[command(subcommand)] diff --git a/crates/cli/src/bin/reggie.rs b/crates/cli/src/bin/reggie.rs new file mode 100644 index 0000000..1c80201 --- /dev/null +++ b/crates/cli/src/bin/reggie.rs @@ -0,0 +1,3 @@ +fn main() -> std::process::ExitCode { + compiler_cli::run() +} diff --git a/crates/cli/src/bin/regulus.rs b/crates/cli/src/bin/regulus.rs new file mode 100644 index 0000000..1c80201 --- /dev/null +++ b/crates/cli/src/bin/regulus.rs @@ -0,0 +1,3 @@ +fn main() -> std::process::ExitCode { + compiler_cli::run() +} diff --git a/crates/cli/src/main.rs b/crates/cli/src/lib.rs similarity index 75% rename from crates/cli/src/main.rs rename to crates/cli/src/lib.rs index 17ecb6b..52668df 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/lib.rs @@ -4,7 +4,7 @@ mod echo; use clap::Parser; -fn main() -> std::process::ExitCode { +pub fn run() -> std::process::ExitCode { let args = args::Args::parse(); commands::run(args.command) } diff --git a/crates/cli/tests/build.rs b/crates/cli/tests/build.rs index 0d8fe58..d858550 100644 --- a/crates/cli/tests/build.rs +++ b/crates/cli/tests/build.rs @@ -9,7 +9,7 @@ fn build_emit_writes_wat_and_debug_artifacts_without_wasm() { let out_dir = unique_temp_dir("regulus_cli_emit_build"); fs::create_dir_all(&out_dir).expect("create output dir"); - let output = Command::new(env!("CARGO_BIN_EXE_compiler_cli")) + let output = Command::new(env!("CARGO_BIN_EXE_reggie")) .arg("build") .arg(&fixture) .arg("--out-dir") @@ -17,7 +17,7 @@ fn build_emit_writes_wat_and_debug_artifacts_without_wasm() { .arg("--emit") .arg("wat,ast,resolved,typed,ir") .output() - .expect("run compiler_cli build"); + .expect("run reggie build"); assert!( output.status.success(), @@ -53,13 +53,13 @@ fn builds_package_owned_overlap_fixture() { let out_dir = unique_temp_dir("regulus_cli_overlap_build"); fs::create_dir_all(&out_dir).expect("create output dir"); - let output = Command::new(env!("CARGO_BIN_EXE_compiler_cli")) + let output = Command::new(env!("CARGO_BIN_EXE_reggie")) .arg("build") .arg(&fixture) .arg("--out-dir") .arg(&out_dir) .output() - .expect("run compiler_cli build"); + .expect("run reggie build"); assert!( output.status.success(), diff --git a/crates/core/src/loader/dependency.rs b/crates/core/src/loader/dependency.rs index 03b36d3..c20cbb3 100644 --- a/crates/core/src/loader/dependency.rs +++ b/crates/core/src/loader/dependency.rs @@ -63,6 +63,10 @@ pub fn load_dependency_interfaces_with_progress( } for (name, dep, _dev) in dependencies { + if is_registry_backed_dependency(name) { + continue; + } + match dependency_root(root, name, dep) { Some(pkg_root) => { let version = dep.get_dep_ver(name, &package_versions, &pkg_root); @@ -124,6 +128,10 @@ pub fn dependency_nodes(packages: &[DependencyPackage], configured: Vec bool { + name == "gleam_stdlib" +} + fn load_package_sources( package: &DependencyPackage, package_index: usize, ) -> Result { @@ -305,6 +313,30 @@ mod tests { assert!(!interface.interface.functions.contains_key("from_hex_cache")); } + #[test] + fn registry_backed_stdlib_dependency_does_not_parse_cached_source() { + let temp = tempfile::tempdir().expect("temp dir"); + let root = temp.path().join("app"); + write( + &root.join("build/packages/gleam_stdlib/src/gleam/io.gleam"), + "@external(javascript, \"../gleam_stdlib.mjs\", \"print\")\npub fn print(string: String) -> Nil\n", + ); + + let interfaces = load_dependency_interfaces( + &root, + &[( + "gleam_stdlib".to_string(), + DependencyToml::Version(">= 0.44.0 and < 2.0.0".to_string()), + false, + )], + target::CompileTarget::Wasmtime, + ) + .expect("dependency interfaces"); + + assert!(interfaces.packages.is_empty()); + assert!(interfaces.modules.is_empty()); + } + #[test] fn dependency_source_loader_discovers_selected_package_modules() { let temp = tempfile::tempdir().expect("temp dir"); diff --git a/docs/website/guide/examples.md b/docs/website/guide/examples.md index 924d347..4f914be 100644 --- a/docs/website/guide/examples.md +++ b/docs/website/guide/examples.md @@ -6,9 +6,9 @@ compiler's current surface area. ## Working examples ```sh -gleam-wasm build examples/scalar_project -gleam-wasm build examples/multi_module_project -gleam-wasm build examples/browser_scalar --target browser +reggie build examples/scalar_project +reggie build examples/multi_module_project +reggie build examples/browser_scalar --target browser ``` ## Example projects diff --git a/docs/website/guide/installation.md b/docs/website/guide/installation.md index ab58fac..8b7940a 100644 --- a/docs/website/guide/installation.md +++ b/docs/website/guide/installation.md @@ -14,7 +14,8 @@ Regulus is developed from source. Build and run it with Cargo. cargo build -p compiler_cli ``` -Run the CLI through Cargo while developing: +This builds the `reggie` and `regulus` binaries. Run the CLI through Cargo +while developing: ```sh cargo run -q -p compiler_cli -- --help diff --git a/docs/website/guide/usage/cli.md b/docs/website/guide/usage/cli.md index d3d7513..b02415f 100644 --- a/docs/website/guide/usage/cli.md +++ b/docs/website/guide/usage/cli.md @@ -1,16 +1,18 @@ # CLI -The CLI binary is named `gleam-wasm`. When running from a checkout, prefix -commands with Cargo: +The CLI binaries are named `reggie` and `regulus`. When running from a +checkout, prefix commands with Cargo: ```sh cargo run -q -p compiler_cli -- build ``` -Installed binaries can be run directly: +Installed binaries can be run directly. The docs use `reggie`, but `regulus` +is also available as an alias: ```sh -gleam-wasm build +reggie build +regulus build ``` ## Build a project @@ -18,9 +20,9 @@ gleam-wasm build Use `build` for normal Gleam projects with a `gleam.toml` file. ```sh -gleam-wasm build -gleam-wasm build examples/scalar_project -gleam-wasm build examples/scalar_project/gleam.toml +reggie build +reggie build examples/scalar_project +reggie build examples/scalar_project/gleam.toml ``` With no project argument, the current directory is used. A directory argument @@ -36,13 +38,13 @@ build/.wasm Use `--output` to choose the exact final Wasm path: ```sh -gleam-wasm build examples/scalar_project --output out/app.wasm +reggie build examples/scalar_project --output out/app.wasm ``` Use `--out-dir` to write compiler-named artifacts into a directory: ```sh -gleam-wasm build examples/scalar_project --out-dir build/examples +reggie build examples/scalar_project --out-dir build/examples ``` Project builds print dependency progress to stderr. Quiet output keeps package @@ -64,7 +66,7 @@ Use `compile` for a single `.gleam` file. This path is useful for small tests, fixtures, and compiler debugging. ```sh -gleam-wasm compile path/to/module.gleam +reggie compile path/to/module.gleam ``` By default, single-file compilation writes a `.wasm` file next to the input. @@ -76,15 +78,15 @@ Use `run` to compile a single `.gleam` file and execute one exported function with Wasmtime. ```sh -gleam-wasm run path/to/module.gleam -gleam-wasm run path/to/module.gleam --function answer -gleam-wasm run path/to/module.gleam --function add 1 2 +reggie run path/to/module.gleam +reggie run path/to/module.gleam --function answer +reggie run path/to/module.gleam --function add 1 2 ``` `run` defaults to the `main` export. The `exec` command is an alias: ```sh -gleam-wasm exec path/to/module.gleam +reggie exec path/to/module.gleam ``` Scalar arguments and return values use the low-level Wasm ABI. `Int` values are @@ -98,8 +100,8 @@ into guest memory at the Wasm boundary. Programs can still print strings through Both `build` and `compile` accept `--target`: ```sh -gleam-wasm build examples/browser_scalar --target browser -gleam-wasm compile path/to/module.gleam --target wasmtime +reggie build examples/browser_scalar --target browser +reggie compile path/to/module.gleam --target wasmtime ``` Supported target values are `wasmtime`, `browser`, and `wasi`. Project builds @@ -110,8 +112,8 @@ use the target from `gleam.toml` when `--target` is not provided. `--emit` selects emitted artifact kinds: ```sh -gleam-wasm build examples/scalar_project --emit wasm,wat -gleam-wasm build examples/scalar_project --emit wat,ast,resolved,typed,ir +reggie build examples/scalar_project --emit wasm,wat +reggie build examples/scalar_project --emit wat,ast,resolved,typed,ir ``` Supported emit values are: @@ -132,7 +134,7 @@ files beside the selected output path unless `--dump-dir` is set. Use `--dump-dir` to write all compiler debug dumps into a separate directory: ```sh -gleam-wasm build examples/multi_module_project --dump-dir build/dumps +reggie build examples/multi_module_project --dump-dir build/dumps ``` Single-file dumps include AST, resolved AST, typed output, IR, and WAT. Project @@ -146,7 +148,7 @@ artifacts are only written when the requested compiler phase completes. Use `list` to inspect discovered modules without building artifacts. ```sh -gleam-wasm list examples/multi_module_project +reggie list examples/multi_module_project ``` ## Current limitations diff --git a/docs/website/guide/usage/index.md b/docs/website/guide/usage/index.md index 710351a..90b042a 100644 --- a/docs/website/guide/usage/index.md +++ b/docs/website/guide/usage/index.md @@ -12,10 +12,10 @@ possible compiler input or when you are debugging one source file. ## Common commands ```sh -gleam-wasm build -gleam-wasm build path/to/project -gleam-wasm compile path/to/module.gleam -gleam-wasm run path/to/module.gleam +reggie build +reggie build path/to/project +reggie compile path/to/module.gleam +reggie run path/to/module.gleam ``` `run` is a single-file helper that compiles a module in memory and executes one diff --git a/docs/website/reference/cli-and-build-outputs.md b/docs/website/reference/cli-and-build-outputs.md index 0aa6339..4541a62 100644 --- a/docs/website/reference/cli-and-build-outputs.md +++ b/docs/website/reference/cli-and-build-outputs.md @@ -5,7 +5,7 @@ intermediate representations without adding test-only entry points. ## Commands -`gleam-wasm build [project]` compiles a Gleam project from `gleam.toml`. +`reggie build [project]` compiles a Gleam project from `gleam.toml`. With no argument it builds the current directory. A directory argument builds that project root, and a `gleam.toml` argument builds the owning project. @@ -15,7 +15,7 @@ artifacts such as `.wasm` and `.wat` into the given directory. `--emit` accepts comma-separated artifact kinds: `wasm`, `wat`, `ast`, `resolved`, `typed`, and `ir`. -`gleam-wasm compile ` compiles one Gleam source file. It runs the same +`reggie compile ` compiles one Gleam source file. It runs the same single-file pipeline used by tests: ```text @@ -26,7 +26,7 @@ The command writes a `.wasm` file next to the input unless `--output` or `--out-dir` is set. `--wat` remains a compatibility alias for emitting WAT. Passing `--wat` without a path uses the `.wat` path matching the output file. -`gleam-wasm list [project]` loads a project and prints discovered modules. It is +`reggie list [project]` loads a project and prints discovered modules. It is an inspection command and does not write artifacts. ## Examples diff --git a/docs/website/reference/supported-subset.md b/docs/website/reference/supported-subset.md index 9545e00..4f43334 100644 --- a/docs/website/reference/supported-subset.md +++ b/docs/website/reference/supported-subset.md @@ -1,7 +1,7 @@ # Supported subset -Regulus currently compiles single-file Gleam programs to WebAssembly through the -full compiler pipeline: +Regulus currently compiles single-file Gleam programs and supported Gleam +projects to WebAssembly through the full compiler pipeline: ```text Gleam source -> parse -> AST -> resolve -> type check -> IR -> Wasm @@ -12,7 +12,7 @@ Gleam source -> parse -> AST -> resolve -> type check -> IR -> Wasm | Area | Status | | --------------------------- | ------------------------------- | | Single-file compilation | Supported | -| Whole-project linked output | Not supported | +| Whole-project linked output | Supported for project modules | | Project discovery | Partial | | Type checking | Broad subset | | Managed runtime values | Partial | @@ -26,6 +26,7 @@ Gleam source -> parse -> AST -> resolve -> type check -> IR -> Wasm ### Inputs - Compile one Gleam source file to `.wasm`. +- Compile supported Gleam projects to one linked `.wasm` artifact. - Load `gleam.toml` and discover project modules. - Filter target-group declarations for Wasmtime, browser, and WASI targets. - Emit optional debug dumps: AST, resolved AST, typed AST, IR, and WAT. @@ -154,7 +155,7 @@ Regulus can: - report missing modules - keep single-file loading available for tests and examples -It does not yet compile a full project into linked Wasm output. +Project builds compile discovered project modules into one linked Wasm output. ### Standard library @@ -190,7 +191,6 @@ The compiler: ### Projects and dependencies -- Whole-project linked Wasm output. - Fetching Hex packages. - Loading dependency source modules. - Linking compiled dependency modules.