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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:

# Workflow

- name: cargo fmt
run: cargo fmt --all --check

- name: cargo build
run: cargo build --locked --verbose
env:
Expand Down
24 changes: 11 additions & 13 deletions cmd/gravity/src/codegen/exports.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use genco::prelude::*;
use wit_bindgen_core::wit_parser::{Function, Param, Resolve, SizeAlign, World, WorldItem};

use crate::go::{imports::CONTEXT_CONTEXT, GoIdentifier, GoResult, GoType};
use crate::go::{GoIdentifier, GoResult, GoType, imports::CONTEXT_CONTEXT};

pub struct ExportConfig<'a> {
pub instance: &'a GoIdentifier,
Expand Down Expand Up @@ -35,12 +35,12 @@ impl<'a> ExportGenerator<'a> {
let params = func
.params
.iter()
.map(
|Param { name, ty, .. }| match crate::resolve_param_type(ty, self.config.resolve) {
.map(|Param { name, ty, .. }| {
match crate::resolve_param_type(ty, self.config.resolve) {
GoType::ValueOrOk(t) => (GoIdentifier::local(name), *t),
t => (GoIdentifier::local(name), t),
},
)
}
})
.collect::<Vec<_>>();

let result = if let Some(wit_type) = &func.result {
Expand Down Expand Up @@ -165,8 +165,10 @@ mod tests {

// Verify function body
assert!(generated.contains("arg0 := value"));
assert!(generated
.contains("i.module.ExportedFunction(\"add_number\").Call(ctx, uint64(result0))"));
assert!(
generated
.contains("i.module.ExportedFunction(\"add_number\").Call(ctx, uint64(result0))")
);
assert!(generated.contains("if err1 != nil {"));
assert!(generated.contains("panic(err1)"));
assert!(generated.contains("results1 := raw1[0]"));
Expand All @@ -193,9 +195,7 @@ mod tests {
/// causing a Go compile error: cannot use uint64 as uint32.
#[test]
fn test_export_variant_u32_no_encode_u32() {
use wit_bindgen_core::wit_parser::{
Case, TypeDef, TypeDefKind, TypeOwner, Variant,
};
use wit_bindgen_core::wit_parser::{Case, TypeDef, TypeDefKind, TypeOwner, Variant};

let mut resolve = Resolve::new();

Expand Down Expand Up @@ -290,9 +290,7 @@ mod tests {
/// Go compile error: cannot use int64 as uint64.
#[test]
fn test_export_variant_u64_no_int64_cast() {
use wit_bindgen_core::wit_parser::{
Case, TypeDef, TypeDefKind, TypeOwner, Variant,
};
use wit_bindgen_core::wit_parser::{Case, TypeDef, TypeDefKind, TypeOwner, Variant};

let mut resolve = Resolve::new();

Expand Down
8 changes: 3 additions & 5 deletions cmd/gravity/src/codegen/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use wit_bindgen_core::{

use crate::{
go::{
comment,
GoIdentifier, GoResult, GoType, Operand, comment,
imports::{
ERRORS_NEW, UTF8_VALID_RUNE, WAZERO_API_DECODE_F32, WAZERO_API_DECODE_F64,
WAZERO_API_DECODE_I32, WAZERO_API_DECODE_U32, WAZERO_API_ENCODE_F32,
WAZERO_API_ENCODE_F64,
},
GoIdentifier, GoResult, GoType, Operand,
},
resolve_type, resolve_wasm_type,
};
Expand Down Expand Up @@ -983,9 +982,8 @@ impl Bindgen for Func<'_> {
};
}

let case_type = GoIdentifier::public(crate::case_dispatch_name(
&name, case, resolve,
));
let case_type =
GoIdentifier::public(crate::case_dispatch_name(&name, case, resolve));
let payload_intro = if all_direct {
quote!()
} else {
Expand Down
9 changes: 3 additions & 6 deletions cmd/gravity/src/codegen/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use crate::{
},
},
go::{
imports::{CONTEXT_CONTEXT, WAZERO_API_MODULE},
GoIdentifier, GoResult, GoType,
imports::{CONTEXT_CONTEXT, WAZERO_API_MODULE},
},
resolve_param_type, resolve_type, resolve_wasm_type,
};
Expand Down Expand Up @@ -167,9 +167,7 @@ impl<'a> ImportAnalyzer<'a> {
let payload = case.ty.as_ref().map(|t| resolve_type(t, self.resolve));
let dispatch = match crate::case_dispatch_kind(case, self.resolve) {
crate::CaseDispatchKind::DirectRecord => CaseDispatch::DirectRecord {
record_type: payload
.clone()
.expect("DirectRecord case has a payload"),
record_type: payload.clone().expect("DirectRecord case has a payload"),
},
crate::CaseDispatchKind::Wrapped => CaseDispatch::Wrapped {
wrapper_name: GoIdentifier::public(format!("{variant_name}-{}", case.name)),
Expand Down Expand Up @@ -415,8 +413,7 @@ impl<'a> ImportCodeGenerator<'a> {
}
TypeDefinition::Variant { cases } => {
let variant_interface = &typ.go_type_name;
let marker_method =
&GoIdentifier::private(format!("is-{}", &typ.name));
let marker_method = &GoIdentifier::private(format!("is-{}", &typ.name));
let case_definitions = cases.iter().map(|case| match &case.dispatch {
CaseDispatch::DirectRecord { record_type } => quote! {
$['\n']
Expand Down
4 changes: 1 addition & 3 deletions examples/regressions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use gravity::regressions::{
bot_verifier, checker, email_checker, ip_source, pinger, processor,
};
use gravity::regressions::{bot_verifier, checker, email_checker, ip_source, pinger, processor};

wit_bindgen::generate!({
world: "regressions",
Expand Down
Loading