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
60 changes: 56 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ members = ["./tests"]

[workspace.dependencies]
anyhow = "1.0.102"
bzip2 = "0.6.1"
once_cell = "1.21.3"
reqwest = { version = "0.13.1", features = ["blocking"] }
tar = "0.4"

[workspace.package]
version = "0.2.0"
Expand All @@ -34,11 +38,17 @@ unnecessary_cast = 'warn'
allow_attributes_without_reason = 'warn'

[dependencies]
anyhow = { workspace = true}
anyhow = { workspace = true }
bzip2 = { workspace = true }
reqwest = { workspace = true }
tar = { workspace = true }
clap = { version = "4.5.60", features = ["derive"] }
regex = "1.12.3"
serde = { version = "1.0.228", features = ["derive"] }
toml = "1.1.0"
wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "3ee9fe20a5bce398360d5d291e81a4224a6d7c76" }
# TODO: Switch to release 0.55.0 when it's available:
wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "6a13b247" }
wit-component = "0.245.1"
wit-parser = "0.245.1"
which = "8.0.2"
dirs = "6.0.0"
19 changes: 10 additions & 9 deletions src/cmd_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use crate::utils::{make_path_absolute, parse_wit};
use crate::utils::make_path_absolute;
use anyhow::Result;
use std::path::{Path, PathBuf};
use wit_parser::{Resolve, WorldId};

#[allow(clippy::too_many_arguments)]
pub fn generate_bindings(
paths: &[impl AsRef<Path>],
worlds: &[String],
ignore_toml_files: bool,
features: &[String],
all_features: bool,
resolve: &mut Resolve,
world: WorldId,
generate_stubs: bool,
should_format: bool,
output: Option<&Path>,
pkg_name: Option<String>,
export_pkg_name: Option<String>,
include_versions: bool,
) -> Result<()> {
let (mut resolve, world) = parse_wit(paths, worlds, ignore_toml_files, features, all_features)?;
let mut files = Default::default();

let format = if should_format {
Expand All @@ -37,13 +36,15 @@ pub fn generate_bindings(
generate_stubs,
format,
pkg_name,
export_pkg_name,
include_versions,
..Default::default()
}
.build()
.generate(&mut resolve, world, &mut files)?;
.generate(resolve, world, &mut files)?;

let output_path = match output {
Some(p) => make_path_absolute(&p.to_path_buf())?,
Some(p) => make_path_absolute(p)?,
None => PathBuf::from("."),
};

Expand Down
22 changes: 8 additions & 14 deletions src/cmd_build.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
use crate::utils::{check_go_version, make_path_absolute};
use anyhow::{Result, anyhow};
use std::{path::PathBuf, process::Command};
use std::{
path::{Path, PathBuf},
process::Command,
};

/// Compiles a Go application to a wasm module with `go build`.
///
/// If the module is not going to be adapted to the component model,
/// set the `only_wasip1` arg to true.
pub fn build_module(
out: Option<&PathBuf>,
go_path: Option<&PathBuf>,
only_wasip1: bool,
) -> Result<PathBuf> {
let go = match &go_path {
Some(p) => make_path_absolute(p)?,
None => PathBuf::from("go"),
};

check_go_version(&go)?;
pub fn build_module(out: Option<&PathBuf>, go: &Path, only_wasip1: bool) -> Result<PathBuf> {
check_go_version(go)?;

let out_path_buf = match &out {
Some(p) => make_path_absolute(p)?,
Expand Down Expand Up @@ -53,13 +47,13 @@ pub fn build_module(
];

let output = if only_wasip1 {
Command::new(&go)
Command::new(go)
.args(module_args)
.env("GOOS", "wasip1")
.env("GOARCH", "wasm")
.output()?
} else {
Command::new(&go)
Command::new(go)
.args(component_args)
.env("GOOS", "wasip1")
.env("GOARCH", "wasm")
Expand Down
13 changes: 4 additions & 9 deletions src/cmd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ use std::{
pub fn build_test_module(
path: &Path,
output_dir: Option<&PathBuf>,
go_path: Option<&PathBuf>,
go: &Path,
only_wasip1: bool,
) -> Result<PathBuf> {
let go = match &go_path {
Some(p) => make_path_absolute(p)?,
None => PathBuf::from("go"),
};

check_go_version(&go)?;
check_go_version(go)?;

let test_wasm_path = {
// The directory in which the test component will be placed
Expand Down Expand Up @@ -68,7 +63,7 @@ pub fn build_test_module(
];

let output = if only_wasip1 {
Command::new(&go)
Command::new(go)
.args(module_args)
.env("GOOS", "wasip1")
.env("GOARCH", "wasm")
Expand All @@ -80,7 +75,7 @@ pub fn build_test_module(

// TODO: for when we figure out how wasip2 tests are to be run
#[allow(unreachable_code)]
Command::new(&go)
Command::new(go)
.args(component_args)
.env("GOOS", "wasip1")
.env("GOARCH", "wasm")
Expand Down
Loading
Loading