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
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# moonbit removed from language matrix for now - causing CI failures
lang: [c, rust, csharp, cpp]
lang: [c, rust, csharp, cpp, go]
exclude:
# For now csharp doesn't work on macos, so exclude it from testing.
- os: macos-latest
Expand All @@ -85,6 +85,12 @@ jobs:
dotnet-version: '9.x'
if: matrix.lang == 'csharp'

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.25.4
if: matrix.lang == 'go'

# Hacky work-around for https://github.com/dotnet/runtime/issues/80619
- run: dotnet new console -o /tmp/foo
if: matrix.os != 'windows-latest' && matrix.lang == 'csharp'
Expand Down
14 changes: 14 additions & 0 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ CLI tool to generate bindings for WIT documents and the component model.
resolver = "2"

[workspace.package]
edition = "2021"
edition = "2024"
version = "0.49.0"
license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT"
repository = "https://github.com/bytecodealliance/wit-bindgen"
rust-version = "1.82.0"
rust-version = "1.85.0"

[workspace.dependencies]
anyhow = "1.0.72"
Expand Down Expand Up @@ -48,6 +48,7 @@ wit-bindgen-rust = { path = "crates/rust", version = "0.49.0" }
wit-bindgen-csharp = { path = 'crates/csharp', version = '0.49.0' }
wit-bindgen-markdown = { path = 'crates/markdown', version = '0.49.0' }
wit-bindgen-moonbit = { path = 'crates/moonbit', version = '0.49.0' }
wit-bindgen-go = { path = 'crates/go', version = '0.49.0' }
wit-bindgen = { path = 'crates/guest-rust', version = '0.49.0', default-features = false }
wit-bindgen-test = { path = 'crates/test', version = '0.49.0' }

Expand All @@ -64,6 +65,7 @@ wit-bindgen-cpp = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-markdown = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-moonbit = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-csharp = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-go = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-test = { workspace = true }
wit-component = { workspace = true }
wasm-encoder = { workspace = true }
Expand All @@ -84,7 +86,7 @@ c = ['dep:wit-bindgen-c']
cpp = ['dep:wit-bindgen-cpp']
rust = ['dep:wit-bindgen-rust']
markdown = ['dep:wit-bindgen-markdown']
go = []
go = ['dep:wit-bindgen-go']
csharp = ['dep:wit-bindgen-csharp']
csharp-mono = ['csharp']
moonbit = ['dep:wit-bindgen-moonbit']
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,11 @@ Now you can build with:
dotnet publish
```

Checkout out [componentize-dotnet](https://github.com/bytecodealliance/componentize-dotnet) for a simplified experience.
Check out [componentize-dotnet](https://github.com/bytecodealliance/componentize-dotnet) for a simplified experience.

### Guest: Go

See the [wit-bindgen-go README.md](crates/go/README.md) for details and generating and using Go bindings.

### Guest: Java

Expand Down
13 changes: 8 additions & 5 deletions ci/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const CRATES_TO_PUBLISH: &[&str] = &[
"wit-bindgen-csharp",
"wit-bindgen-markdown",
"wit-bindgen-moonbit",
"wit-bindgen-go",
"wit-bindgen-rust-macro",
"wit-bindgen-rt",
"wit-bindgen",
Expand Down Expand Up @@ -65,11 +66,13 @@ fn main() {
bump_version(&krate, &crates, name == "bump-patch");
}
// update the lock file
assert!(Command::new("cargo")
.arg("fetch")
.status()
.unwrap()
.success());
assert!(
Command::new("cargo")
.arg("fetch")
.status()
.unwrap()
.success()
);
}

"publish" => {
Expand Down
2 changes: 1 addition & 1 deletion ci/rebuild-libwit-bindgen-cabi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub unsafe extern "C" fn $realloc(
align: usize,
new_len: usize,
) -> *mut u8 {
crate::rt::cabi_realloc(old_ptr, old_len, align, new_len)
unsafe { crate::rt::cabi_realloc(old_ptr, old_len, align, new_len) }
}
EOF

Expand Down
4 changes: 2 additions & 2 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use wit_bindgen_core::abi::{
self, AbiVariant, Bindgen, Bitcast, Instruction, LiftLower, WasmSignature, WasmType,
};
use wit_bindgen_core::{
dealias, uwrite, uwriteln, wit_parser::*, AnonymousTypeGenerator, AsyncFilterSet, Direction,
Files, InterfaceGenerator as _, Ns, WorldGenerator,
AnonymousTypeGenerator, AsyncFilterSet, Direction, Files, InterfaceGenerator as _, Ns,
WorldGenerator, dealias, uwrite, uwriteln, wit_parser::*,
};
use wit_component::StringEncoding;

Expand Down
15 changes: 12 additions & 3 deletions crates/core/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::iter;

pub use wit_parser::abi::{AbiVariant, FlatTypes, WasmSignature, WasmType};
use wit_parser::{
align_to_arch, Alignment, ArchitectureSize, ElementInfo, Enum, Flags, FlagsRepr, Function,
Handle, Int, Record, Resolve, Result_, SizeAlign, Tuple, Type, TypeDefKind, TypeId, Variant,
Alignment, ArchitectureSize, ElementInfo, Enum, Flags, FlagsRepr, Function, Handle, Int,
Record, Resolve, Result_, SizeAlign, Tuple, Type, TypeDefKind, TypeId, Variant, align_to_arch,
};

// Helper macro for defining instructions without having to have tons of
Expand Down Expand Up @@ -806,6 +806,12 @@ pub fn guest_export_needs_post_return(resolve: &Resolve, func: &Function) -> boo
.unwrap_or(false)
}

pub fn guest_export_params_have_allocations(resolve: &Resolve, func: &Function) -> bool {
func.params
.iter()
.any(|(_, t)| needs_deallocate(resolve, &t, Deallocate::Lists))
}

fn needs_deallocate(resolve: &Resolve, ty: &Type, what: Deallocate) -> bool {
match ty {
Type::String => true,
Expand Down Expand Up @@ -1134,7 +1140,10 @@ impl<'a, B: Bindgen> Generator<'a, B> {
for (param_name, ty) in func.params.iter() {
let Some(types) = flat_types(self.resolve, ty, Some(max_flat_params))
else {
panic!("failed to flatten types during direct parameter lifting ('{param_name}' in func '{}')", func.name);
panic!(
"failed to flatten types during direct parameter lifting ('{param_name}' in func '{}')",
func.name
);
};
for _ in 0..types.len() {
self.emit(&Instruction::GetArg { nth: offset });
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/async_.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use std::collections::HashSet;
use std::fmt;
use wit_parser::{Function, FunctionKind, Resolve, WorldKey};
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub trait InterfaceGenerator<'a> {
fn type_record(&mut self, id: TypeId, name: &str, record: &Record, docs: &Docs);
fn type_resource(&mut self, id: TypeId, name: &str, docs: &Docs);
fn type_flags(&mut self, id: TypeId, name: &str, flags: &Flags, docs: &Docs);
fn type_tuple(&mut self, id: TypeId, name: &str, flags: &Tuple, docs: &Docs);
fn type_tuple(&mut self, id: TypeId, name: &str, tuple: &Tuple, docs: &Docs);
fn type_variant(&mut self, id: TypeId, name: &str, variant: &Variant, docs: &Docs);
fn type_option(&mut self, id: TypeId, name: &str, payload: &Type, docs: &Docs);
fn type_result(&mut self, id: TypeId, name: &str, result: &Result_, docs: &Docs);
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/source.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::btree_map::Entry;
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
use std::fmt::{self, Write};
use std::ops::Deref;

Expand Down
Loading
Loading