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
5 changes: 5 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ echo "export PATH=$DOTNET_PATH:\$PATH" >> ~/.bashrc
# Moonbit
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
echo 'export PATH="$HOME/.moon/bin:$PATH"' >> ~/.bashrc

# Go
curl -OL https://go.dev/dl/go1.25.5.linux-amd64.tar.gz
tar xf go1.25.5.linux-amd64.tar.gz
echo "export PATH=$HOME/go1.25.5.linux-amd64/bin:\$PATH" >> ~/.bashrc
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,11 @@ jobs:
- name: Report failure on cancellation
if: ${{ contains(needs.*.result, 'cancelled') || cancelled() }}
run: exit 1

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: rustup update stable --no-self-update && rustup default stable
- run: rustup component add clippy
- run: cargo clippy --workspace --all-targets -- -D warnings
18 changes: 18 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ description = """
CLI tool to generate bindings for WIT documents and the component model.
"""

[lints]
workspace = true

[workspace]
resolver = "2"

Expand Down Expand Up @@ -52,6 +55,21 @@ wit-bindgen-go = { path = 'crates/go', version = '0.50.0' }
wit-bindgen = { path = 'crates/guest-rust', version = '0.50.0', default-features = false }
wit-bindgen-test = { path = 'crates/test', version = '0.50.0' }

[workspace.lints.clippy]
# The default set of lints in Clippy is viewed as "too noisy" right now so
# they're all turned off by default. Selective lints are then enabled below as
# necessary.
all = { level = 'allow', priority = -1 }
clone_on_copy = 'warn'
map_clone = 'warn'
unnecessary_to_owned = 'warn'
manual_strip = 'warn'
uninlined_format_args = 'warn'
unnecessary_mut_passed = 'warn'
unnecessary_fallible_conversions = 'warn'
unnecessary_cast = 'warn'
allow_attributes_without_reason = 'warn'

[[bin]]
name = "wit-bindgen"

Expand Down
3 changes: 3 additions & 0 deletions crates/c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ C bindings generator for WIT and the component model, typically used through the
`wit-bindgen-cli` crate.
"""

[lints]
workspace = true

[lib]
doctest = false
test = false
Expand Down
51 changes: 24 additions & 27 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,36 +662,36 @@ impl C {
match cast {
Bitcast::I32ToF32 | Bitcast::I64ToF32 => {
self.needs_union_int32_float = true;
format!("((union int32_float){{ (int32_t) {} }}).b", op)
format!("((union int32_float){{ (int32_t) {op} }}).b")
}
Bitcast::F32ToI32 | Bitcast::F32ToI64 => {
self.needs_union_float_int32 = true;
format!("((union float_int32){{ {} }}).b", op)
format!("((union float_int32){{ {op} }}).b")
}
Bitcast::I64ToF64 => {
self.needs_union_int64_double = true;
format!("((union int64_double){{ (int64_t) {} }}).b", op)
format!("((union int64_double){{ (int64_t) {op} }}).b")
}
Bitcast::F64ToI64 => {
self.needs_union_double_int64 = true;
format!("((union double_int64){{ {} }}).b", op)
format!("((union double_int64){{ {op} }}).b")
}
Bitcast::I32ToI64 | Bitcast::LToI64 | Bitcast::PToP64 => {
format!("(int64_t) {}", op)
format!("(int64_t) {op}")
}
Bitcast::I64ToI32 | Bitcast::I64ToL => {
format!("(int32_t) {}", op)
format!("(int32_t) {op}")
}
// P64 is currently represented as int64_t, so no conversion is needed.
Bitcast::I64ToP64 | Bitcast::P64ToI64 => {
format!("{}", op)
format!("{op}")
}
Bitcast::P64ToP | Bitcast::I32ToP | Bitcast::LToP => {
format!("(uint8_t *) {}", op)
format!("(uint8_t *) {op}")
}

// Cast to uintptr_t to avoid implicit pointer-to-int conversions.
Bitcast::PToI32 | Bitcast::PToL => format!("(uintptr_t) {}", op),
Bitcast::PToI32 | Bitcast::PToL => format!("(uintptr_t) {op}"),

Bitcast::I32ToL | Bitcast::LToI32 | Bitcast::None => op.to_string(),

Expand Down Expand Up @@ -2034,7 +2034,7 @@ impl InterfaceGenerator<'_> {
let mut f = FunctionBindgen::new(self, c_sig, &import_name);
for (pointer, param) in f.sig.params.iter() {
if *pointer {
f.params.push(format!("*{}", param));
f.params.push(format!("*{param}"));
} else {
f.params.push(param.clone());
}
Expand Down Expand Up @@ -2332,7 +2332,7 @@ void {name}_return({return_ty}) {{
} else if single_ret {
"ret".into()
} else {
format!("ret{}", i)
format!("ret{i}")
};
self.src.h_fns(&name);
retptrs.push(name);
Expand Down Expand Up @@ -2897,7 +2897,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
) {
self.load(ty, offset, operands, results);
let result = results.pop().unwrap();
results.push(format!("(int32_t) {}", result));
results.push(format!("(int32_t) {result}"));
}

fn store(&mut self, ty: &str, offset: ArchitectureSize, operands: &[String]) {
Expand Down Expand Up @@ -2930,10 +2930,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
&& self.r#gen.autodrop_enabled()
&& self.r#gen.contains_droppable_borrow(ty)
{
panic!(
"Unable to autodrop borrows in `{}` values, please disable autodrop",
context
)
panic!("Unable to autodrop borrows in `{context}` values, please disable autodrop")
}
}
}
Expand Down Expand Up @@ -3055,7 +3052,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
}
Instruction::RecordLift { ty, record, .. } => {
let name = self.r#gen.r#gen.type_name(&Type::Id(*ty));
let mut result = format!("({}) {{\n", name);
let mut result = format!("({name}) {{\n");
for (field, op) in record.fields.iter().zip(operands.iter()) {
let field_ty = self.r#gen.r#gen.type_name(&field.ty);
uwriteln!(result, "({}) {},", field_ty, op);
Expand All @@ -3067,12 +3064,12 @@ impl Bindgen for FunctionBindgen<'_, '_> {
Instruction::TupleLower { tuple, .. } => {
let op = &operands[0];
for i in 0..tuple.types.len() {
results.push(format!("({}).f{}", op, i));
results.push(format!("({op}).f{i}"));
}
}
Instruction::TupleLift { ty, tuple, .. } => {
let name = self.r#gen.r#gen.type_name(&Type::Id(*ty));
let mut result = format!("({}) {{\n", name);
let mut result = format!("({name}) {{\n");
for (ty, op) in tuple.types.iter().zip(operands.iter()) {
let ty = self.r#gen.r#gen.type_name(&ty);
uwriteln!(result, "({}) {},", ty, op);
Expand Down Expand Up @@ -3151,7 +3148,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {

Instruction::VariantPayloadName => {
let name = self.locals.tmp("payload");
results.push(format!("*{}", name));
results.push(format!("*{name}"));
self.payloads.push(name);
}

Expand Down Expand Up @@ -3229,7 +3226,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
assert!(block_results.len() == (case.ty.is_some() as usize));

if let Some(_) = case.ty.as_ref() {
let mut dst = format!("{}.val", result);
let mut dst = format!("{result}.val");
dst.push_str(".");
dst.push_str(&to_c_ident(&case.name));
self.store_op(&block_results[0], &dst);
Expand Down Expand Up @@ -3665,7 +3662,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
Some(Scalar::OptionBool(_)) => {
assert_eq!(operands.len(), 1);
let variant = &operands[0];
self.store_in_retptr(&format!("{}.val", variant));
self.store_in_retptr(&format!("{variant}.val"));
self.src.push_str("return ");
self.src.push_str(&variant);
self.src.push_str(".is_some;\n");
Expand All @@ -3677,7 +3674,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
uwriteln!(self.src, "if (!{}.is_err) {{", variant);
if ok.is_some() {
if ok.is_some() {
self.store_in_retptr(&format!("{}.val.ok", variant));
self.store_in_retptr(&format!("{variant}.val.ok"));
} else {
self.empty_return_value();
}
Expand All @@ -3689,7 +3686,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
);
if err.is_some() {
if err.is_some() {
self.store_in_retptr(&format!("{}.val.err", variant));
self.store_in_retptr(&format!("{variant}.val.err"));
} else {
self.empty_return_value();
}
Expand Down Expand Up @@ -3797,7 +3794,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
}

Instruction::Flush { amt } => {
results.extend(operands.iter().take(*amt).map(|v| v.clone()));
results.extend(operands.iter().take(*amt).cloned());
}

Instruction::AsyncTaskReturn { name, params } => {
Expand All @@ -3815,7 +3812,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
params: params
.iter()
.zip(operands)
.map(|(a, b)| (a.clone(), b.clone()))
.map(|(a, b)| (*a, b.clone()))
.collect(),
};
}
Expand Down Expand Up @@ -3928,7 +3925,7 @@ pub fn flags_repr(f: &Flags) -> Int {
FlagsRepr::U16 => Int::U16,
FlagsRepr::U32(1) => Int::U32,
FlagsRepr::U32(2) => Int::U64,
repr => panic!("unimplemented flags {:?}", repr),
repr => panic!("unimplemented flags {repr:?}"),
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Low-level support for bindings generation based on WIT files for use with
`wit-bindgen-cli` and other languages.
"""

[lints]
workspace = true

[lib]
doctest = false

Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ macro_rules! def_instruction {

impl $name<'_> {
/// How many operands does this instruction pop from the stack?
#[allow(unused_variables)]
#[allow(unused_variables, reason = "match arms bind fields for exhaustiveness, not usage")]
pub fn operands_len(&self) -> usize {
match self {
$(
Expand All @@ -51,7 +51,7 @@ macro_rules! def_instruction {
}

/// How many results does this instruction push onto the stack?
#[allow(unused_variables)]
#[allow(unused_variables, reason = "match arms bind fields for exhaustiveness, not usage")]
pub fn results_len(&self) -> usize {
match self {
$(
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Ns {
if self.defined.insert(name.to_string()) {
Ok(())
} else {
Err(format!("name `{}` already defined", name))
Err(format!("name `{name}` already defined"))
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/cpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ description = """
C++ guest and host binding generator for WIT and the component model.
"""

[lints]
workspace = true

[lib]
doctest = false
test = false
Expand Down
Loading
Loading