Skip to content

Commit 8d14951

Browse files
authored
Merge pull request #37 from dicej/auto-download-go
automatically download appropriate Go version when necessary
2 parents f476894 + 8094c1e commit 8d14951

9 files changed

Lines changed: 399 additions & 179 deletions

File tree

Cargo.lock

Lines changed: 56 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ members = ["./tests"]
1313

1414
[workspace.dependencies]
1515
anyhow = "1.0.102"
16+
bzip2 = "0.6.1"
17+
once_cell = "1.21.3"
18+
reqwest = { version = "0.13.1", features = ["blocking"] }
19+
tar = "0.4"
1620

1721
[workspace.package]
1822
version = "0.2.0"
@@ -34,11 +38,17 @@ unnecessary_cast = 'warn'
3438
allow_attributes_without_reason = 'warn'
3539

3640
[dependencies]
37-
anyhow = { workspace = true}
41+
anyhow = { workspace = true }
42+
bzip2 = { workspace = true }
43+
reqwest = { workspace = true }
44+
tar = { workspace = true }
3845
clap = { version = "4.5.60", features = ["derive"] }
3946
regex = "1.12.3"
4047
serde = { version = "1.0.228", features = ["derive"] }
4148
toml = "1.1.0"
42-
wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "3ee9fe20a5bce398360d5d291e81a4224a6d7c76" }
49+
# TODO: Switch to release 0.55.0 when it's available:
50+
wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "6a13b247" }
4351
wit-component = "0.245.1"
4452
wit-parser = "0.245.1"
53+
which = "8.0.2"
54+
dirs = "6.0.0"

src/cmd_bindings.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
use crate::utils::{make_path_absolute, parse_wit};
1+
use crate::utils::make_path_absolute;
22
use anyhow::Result;
33
use std::path::{Path, PathBuf};
4+
use wit_parser::{Resolve, WorldId};
45

56
#[allow(clippy::too_many_arguments)]
67
pub fn generate_bindings(
7-
paths: &[impl AsRef<Path>],
8-
worlds: &[String],
9-
ignore_toml_files: bool,
10-
features: &[String],
11-
all_features: bool,
8+
resolve: &mut Resolve,
9+
world: WorldId,
1210
generate_stubs: bool,
1311
should_format: bool,
1412
output: Option<&Path>,
1513
pkg_name: Option<String>,
14+
export_pkg_name: Option<String>,
15+
include_versions: bool,
1616
) -> Result<()> {
17-
let (mut resolve, world) = parse_wit(paths, worlds, ignore_toml_files, features, all_features)?;
1817
let mut files = Default::default();
1918

2019
let format = if should_format {
@@ -37,13 +36,15 @@ pub fn generate_bindings(
3736
generate_stubs,
3837
format,
3938
pkg_name,
39+
export_pkg_name,
40+
include_versions,
4041
..Default::default()
4142
}
4243
.build()
43-
.generate(&mut resolve, world, &mut files)?;
44+
.generate(resolve, world, &mut files)?;
4445

4546
let output_path = match output {
46-
Some(p) => make_path_absolute(&p.to_path_buf())?,
47+
Some(p) => make_path_absolute(p)?,
4748
None => PathBuf::from("."),
4849
};
4950

src/cmd_build.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
use crate::utils::{check_go_version, make_path_absolute};
22
use anyhow::{Result, anyhow};
3-
use std::{path::PathBuf, process::Command};
3+
use std::{
4+
path::{Path, PathBuf},
5+
process::Command,
6+
};
47

58
/// Compiles a Go application to a wasm module with `go build`.
69
///
710
/// If the module is not going to be adapted to the component model,
811
/// set the `only_wasip1` arg to true.
9-
pub fn build_module(
10-
out: Option<&PathBuf>,
11-
go_path: Option<&PathBuf>,
12-
only_wasip1: bool,
13-
) -> Result<PathBuf> {
14-
let go = match &go_path {
15-
Some(p) => make_path_absolute(p)?,
16-
None => PathBuf::from("go"),
17-
};
18-
19-
check_go_version(&go)?;
12+
pub fn build_module(out: Option<&PathBuf>, go: &Path, only_wasip1: bool) -> Result<PathBuf> {
13+
check_go_version(go)?;
2014

2115
let out_path_buf = match &out {
2216
Some(p) => make_path_absolute(p)?,
@@ -53,13 +47,13 @@ pub fn build_module(
5347
];
5448

5549
let output = if only_wasip1 {
56-
Command::new(&go)
50+
Command::new(go)
5751
.args(module_args)
5852
.env("GOOS", "wasip1")
5953
.env("GOARCH", "wasm")
6054
.output()?
6155
} else {
62-
Command::new(&go)
56+
Command::new(go)
6357
.args(component_args)
6458
.env("GOOS", "wasip1")
6559
.env("GOARCH", "wasm")

src/cmd_test.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@ use std::{
1212
pub fn build_test_module(
1313
path: &Path,
1414
output_dir: Option<&PathBuf>,
15-
go_path: Option<&PathBuf>,
15+
go: &Path,
1616
only_wasip1: bool,
1717
) -> Result<PathBuf> {
18-
let go = match &go_path {
19-
Some(p) => make_path_absolute(p)?,
20-
None => PathBuf::from("go"),
21-
};
22-
23-
check_go_version(&go)?;
18+
check_go_version(go)?;
2419

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

7065
let output = if only_wasip1 {
71-
Command::new(&go)
66+
Command::new(go)
7267
.args(module_args)
7368
.env("GOOS", "wasip1")
7469
.env("GOARCH", "wasm")
@@ -80,7 +75,7 @@ pub fn build_test_module(
8075

8176
// TODO: for when we figure out how wasip2 tests are to be run
8277
#[allow(unreachable_code)]
83-
Command::new(&go)
78+
Command::new(go)
8479
.args(component_args)
8580
.env("GOOS", "wasip1")
8681
.env("GOARCH", "wasm")

0 commit comments

Comments
 (0)