Skip to content
Open
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
145 changes: 112 additions & 33 deletions Cargo.lock

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

18 changes: 15 additions & 3 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,10 +38,18 @@ 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"
wat = { version = "1.245.1"}
wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "3ee9fe20a5bce398360d5d291e81a4224a6d7c76" }
serde = { version = "1.0.228", features = ["derive"] }
toml = "1.1.0"
# TODO: Switch back to upstream once
# https://github.com/bytecodealliance/wit-bindgen/pull/1572 is merged:
wit-bindgen-go = { git = "https://github.com/dicej/wit-bindgen", rev = "661ade1e" }
wit-component = "0.245.1"
wit-parser = "0.245.1"
which = "8.0.2"
dirs = "6.0.0"
18 changes: 10 additions & 8 deletions src/cmd_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,19 +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(
wit_path: &[impl AsRef<Path>],
world: Option<&str>,
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(wit_path, world, features, all_features)?;
let mut files = Default::default();

let format = if should_format {
Expand All @@ -36,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
38 changes: 10 additions & 28 deletions src/cmd_build.rs
Original file line number Diff line number Diff line change
@@ -1,23 +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(
go_module: Option<&PathBuf>,
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 All @@ -33,22 +26,11 @@ pub fn build_module(
.to_str()
.ok_or_else(|| anyhow!("Output path is not valid unicode"))?;

let module_path = match &go_module {
Some(p) => {
if !p.is_dir() {
return Err(anyhow!("Module path '{}' is not a directory", p.display()));
}
p.to_str()
.ok_or_else(|| anyhow!("Module path is not valid unicode"))?
}
None => ".",
};

// The -buildmode flag mutes the module's output, so it is ommitted
let module_args = [
"build",
"-C",
module_path,
".",
"-ldflags=-checklinkname=0",
"-o",
out_path,
Expand All @@ -57,21 +39,21 @@ pub fn build_module(
let component_args = [
"build",
"-C",
module_path,
".",
"-buildmode=c-shared",
"-ldflags=-checklinkname=0",
"-o",
out_path,
];

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
Loading
Loading