Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix std feature in wasm-encoder #1961

Merged
merged 7 commits into from
Jan 22, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ jobs:
- run: cargo check --no-default-features -p wat --features component-model
- run: cargo check --no-default-features -p wat --features dwarf
- run: cargo check --no-default-features -p wasm-encoder
- run: cargo check --no-default-features -p wasm-encoder --target x86_64-unknown-none
- run: cargo check --no-default-features -p wasm-encoder --target x86_64-unknown-none --features wasmparser,component-model
- run: cargo check --no-default-features -p wasm-encoder --features component-model
- run: cargo check --no-default-features -p wasm-encoder --features wasmparser
- run: cargo check --no-default-features -p wasm-smith
Expand Down
12 changes: 8 additions & 4 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ comfy-table = { version = "7.1.3", default-features = false }
criterion = { version = "0.5.1", default-features = false }
env_logger = "0.11"
indexmap = { version = "2.7.0", default-features = false }
leb128 = "0.2.4"
leb128fmt = { version = "0.1.0", default-features = false }
libfuzzer-sys = "0.4.0"
log = "0.4.17"
num_cpus = "1.13"
Expand All @@ -103,12 +103,12 @@ gimli = "0.30.0"
id-arena = "2"

wasm-compose = { version = "0.224.0", path = "crates/wasm-compose" }
wasm-encoder = { version = "0.224.0", path = "crates/wasm-encoder", default-features = false, features = ["std"] }
wasm-encoder = { version = "0.224.0", path = "crates/wasm-encoder", default-features = false }
wasm-metadata = { version = "0.224.0", path = "crates/wasm-metadata" }
wasm-mutate = { version = "0.224.0", path = "crates/wasm-mutate" }
wasm-shrink = { version = "0.224.0", path = "crates/wasm-shrink" }
wasm-smith = { version = "0.224.0", path = "crates/wasm-smith" }
wasmparser = { version = "0.224.0", path = "crates/wasmparser", default-features = false, features = ['std', 'simd'] }
wasmparser = { version = "0.224.0", path = "crates/wasmparser", default-features = false, features = ['simd'] }
wasmprinter = { version = "0.224.0", path = "crates/wasmprinter", default-features = false }
wast = { version = "224.0.0", path = "crates/wast", default-features = false }
wat = { version = "1.224.0", path = "crates/wat", default-features = false }
Expand All @@ -129,7 +129,7 @@ wat = { workspace = true, features = ['dwarf', 'component-model'] }
termcolor = { workspace = true }

# Dependencies of `validate`
wasmparser = { workspace = true, optional = true, features = ['component-model', 'simd'] }
wasmparser = { workspace = true, optional = true, features = ['std', 'component-model', 'simd'] }
rayon = { workspace = true, optional = true }
bitflags = { workspace = true, optional = true }

Expand All @@ -150,7 +150,7 @@ wasm-shrink = { workspace = true, features = ["clap"], optional = true }
wasm-mutate = { workspace = true, features = ["clap"], optional = true }

# Dependencies of `strip`
wasm-encoder = { workspace = true, optional = true }
wasm-encoder = { workspace = true, features = ["std"], optional = true }
regex = { version = "1.6.0", optional = true }

# Dependencies of `compose`
Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ arbitrary = { workspace = true, features = ["derive"] }
wasm-mutate = { workspace = true }
wasm-shrink = { workspace = true }
wasm-smith = { workspace = true }
wasmparser = { workspace = true }
wasmparser = { workspace = true, features = ["std"] }
wasmprinter = { workspace = true }
wast = { workspace = true }
wat = { workspace = true }
4 changes: 2 additions & 2 deletions crates/wasm-compose/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ workspace = true

[dependencies]
wat = { workspace = true }
wasm-encoder = { workspace = true, features = ['wasmparser', 'component-model'] }
wasmparser = { workspace = true, features = ['validate', 'component-model', 'features'] }
wasm-encoder = { workspace = true, features = ['std', 'wasmparser', 'component-model'] }
wasmparser = { workspace = true, features = ['std', 'validate', 'component-model', 'features'] }
indexmap = { workspace = true, features = ["serde"] }
anyhow = { workspace = true }
serde = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-encoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ all-features = true
workspace = true

[dependencies]
leb128 = { workspace = true }
leb128fmt.workspace = true

# Enable this dependency to get a bunch of `From<wasmparser::Foo> for
# wasm_encoder::Foo` impls.
Expand All @@ -36,7 +36,7 @@ wasmprinter = { workspace = true }
default = ['std', 'component-model']

# A feature which enables implementations of `std::error::Error` as appropriate.
std = []
std = ["wasmparser?/std"]

# On-by-default: conditional support for emitting components in addition to
# core modules.
Expand Down
5 changes: 1 addition & 4 deletions crates/wasm-encoder/src/core/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4001,10 +4001,7 @@ impl ConstExpr {
if prefix != 0xd2 {
return None;
}
leb128::read::unsigned(&mut &self.bytes[1..])
.ok()?
.try_into()
.ok()
leb128fmt::decode_uint_slice::<u32, 32>(&self.bytes[1..], &mut 0).ok()
}
}

Expand Down
21 changes: 15 additions & 6 deletions crates/wasm-encoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,29 @@ impl Encode for usize {

impl Encode for u32 {
fn encode(&self, sink: &mut Vec<u8>) {
leb128::write::unsigned(sink, (*self).into()).unwrap();
let (value, pos) = leb128fmt::encode_u32(*self).unwrap();
sink.extend_from_slice(&value[..pos]);
}
}

impl Encode for i32 {
fn encode(&self, sink: &mut Vec<u8>) {
leb128::write::signed(sink, (*self).into()).unwrap();
let (value, pos) = leb128fmt::encode_s32(*self).unwrap();
sink.extend_from_slice(&value[..pos]);
}
}

impl Encode for u64 {
fn encode(&self, sink: &mut Vec<u8>) {
leb128::write::unsigned(sink, *self).unwrap();
let (value, pos) = leb128fmt::encode_u64(*self).unwrap();
sink.extend_from_slice(&value[..pos]);
}
}

impl Encode for i64 {
fn encode(&self, sink: &mut Vec<u8>) {
leb128::write::signed(sink, *self).unwrap();
let (value, pos) = leb128fmt::encode_s64(*self).unwrap();
sink.extend_from_slice(&value[..pos]);
}
}

Expand Down Expand Up @@ -200,8 +204,8 @@ where
}

fn encoding_size(n: u32) -> usize {
let mut buf = [0u8; 5];
leb128::write::unsigned(&mut &mut buf[..], n.into()).unwrap()
let (_value, pos) = leb128fmt::encode_u32(n).unwrap();
pos
}

fn encode_section(sink: &mut Vec<u8>, count: u32, bytes: &[u8]) {
Expand All @@ -214,6 +218,11 @@ fn encode_section(sink: &mut Vec<u8>, count: u32, bytes: &[u8]) {
mod test {
use super::*;

#[test]
fn test_encoding_size() {
assert_eq!(encoding_size(624485), 3);
}

#[test]
fn it_encodes_an_empty_module() {
let bytes = Module::new().finish();
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ workspace = true
[dependencies]
clap = { workspace = true, optional = true }
anyhow = { workspace = true }
wasmparser = { workspace = true, features = ['component-model', 'hash-collections'] }
wasm-encoder = { workspace = true, features = ['component-model'] }
wasmparser = { workspace = true, features = ['std', 'component-model', 'hash-collections'] }
wasm-encoder = { workspace = true, features = ['std', 'component-model'] }
indexmap = { workspace = true, features = ["serde"] }
serde = { workspace = true }
serde_derive = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-mutate-stats/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ num_cpus = { workspace = true }
rand = { workspace = true }
wasm-mutate = { workspace = true }
wasmprinter = { workspace = true }
wasmparser = { workspace = true, features = ['validate'] }
wasmparser = { workspace = true, features = ['std', 'validate'] }
wasmtime = { workspace = true }
env_logger = { workspace = true }
itertools = "0.13.0"
Expand Down
6 changes: 3 additions & 3 deletions crates/wasm-mutate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ workspace = true
[dependencies]
clap = { workspace = true, optional = true }
thiserror = "1.0.28"
wasmparser = { workspace = true, features = ['simd'] }
wasm-encoder = { workspace = true, features = ['wasmparser'] }
wasmparser = { workspace = true, features = ['std', 'simd'] }
wasm-encoder = { workspace = true, features = ['std', 'wasmparser'] }
rand = { workspace = true }
log = { workspace = true }
egg = "0.6.0"
Expand All @@ -24,4 +24,4 @@ anyhow = { workspace = true }
wat = { workspace = true }
wasmprinter = { workspace = true }
env_logger = { workspace = true }
wasmparser = { workspace = true, features = ['validate', 'features', 'simd'] }
wasmparser = { workspace = true, features = ['std', 'validate', 'features', 'simd'] }
2 changes: 1 addition & 1 deletion crates/wasm-shrink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ log = { workspace = true }
rand = { workspace = true }
clap = { workspace = true, optional = true }
wasm-mutate = { workspace = true }
wasmparser = { workspace = true, features = ['validate', 'features'] }
wasmparser = { workspace = true, features = ['std', 'validate', 'features'] }

[dev-dependencies]
env_logger = { workspace = true }
Expand Down
8 changes: 3 additions & 5 deletions crates/wasm-smith/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ anyhow = { workspace = true }
arbitrary = { workspace = true, features = ["derive"] }
clap = { workspace = true, optional = true }
flagset = "0.4"
indexmap = { workspace = true }
leb128 = { workspace = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
wasm-encoder = { workspace = true }
wasmparser = { workspace = true, optional = true, features = ['validate', 'features', 'simd'] }
wasm-encoder = { workspace = true, features = ['std'] }
wasmparser = { workspace = true, optional = true, features = ['std', 'validate', 'features', 'simd'] }
wat = { workspace = true, optional = true }

[dev-dependencies]
criterion = { workspace = true }
rand = { workspace = true }
wasmparser = { workspace = true, features = ['validate', 'features', 'simd'] }
wasmparser = { workspace = true, features = ['std', 'validate', 'features', 'simd'] }
wasmprinter = { workspace = true }
wat = { workspace = true }

Expand Down
4 changes: 2 additions & 2 deletions crates/wast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ all-features = true
workspace = true

[dependencies]
leb128 = { workspace = true }
leb128fmt = { workspace = true }
unicode-width = "0.2.0"
memchr = "2.4.1"
wasm-encoder = { workspace = true }
wasm-encoder = { workspace = true, features = ['std'] }
bumpalo = "3.14.0"
gimli = { workspace = true, optional = true }

Expand Down
12 changes: 8 additions & 4 deletions crates/wast/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,29 @@ impl Encode for u8 {

impl Encode for u32 {
fn encode(&self, e: &mut Vec<u8>) {
leb128::write::unsigned(e, (*self).into()).unwrap();
let (value, pos) = leb128fmt::encode_u32(*self).unwrap();
e.extend_from_slice(&value[..pos]);
}
}

impl Encode for i32 {
fn encode(&self, e: &mut Vec<u8>) {
leb128::write::signed(e, (*self).into()).unwrap();
let (value, pos) = leb128fmt::encode_s32(*self).unwrap();
e.extend_from_slice(&value[..pos]);
}
}

impl Encode for u64 {
fn encode(&self, e: &mut Vec<u8>) {
leb128::write::unsigned(e, *self).unwrap();
let (value, pos) = leb128fmt::encode_u64(*self).unwrap();
e.extend_from_slice(&value[..pos]);
}
}

impl Encode for i64 {
fn encode(&self, e: &mut Vec<u8>) {
leb128::write::signed(e, *self).unwrap();
let (value, pos) = leb128fmt::encode_s64(*self).unwrap();
e.extend_from_slice(&value[..pos]);
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/wit-component/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ workspace = true
all-features = true

[dependencies]
wasmparser = { workspace = true, features = ['component-model', 'simd'] }
wasm-encoder = { workspace = true, features = ["wasmparser"] }
wasmparser = { workspace = true, features = ['std', 'component-model', 'simd'] }
wasm-encoder = { workspace = true, features = ['std', 'wasmparser'] }
wasm-metadata = { workspace = true }
wit-parser = { workspace = true, features = ['decoding', 'serde'] }
anyhow = { workspace = true }
Expand All @@ -35,7 +35,7 @@ serde_derive = { workspace = true }
serde_json = { workspace = true }

[dev-dependencies]
wasmparser = { workspace = true, features = ['component-model', 'features'] }
wasmparser = { workspace = true, features = ['std', 'component-model', 'features'] }
wasmprinter = { workspace = true, features = ['component-model'] }
glob = "0.3.0"
pretty_assertions = "1.3.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ log = { workspace = true }
semver = { workspace = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
wasmparser = { workspace = true, optional = true, features = ['validate', 'component-model', 'features'] }
wasmparser = { workspace = true, optional = true, features = ['std', 'validate', 'component-model', 'features'] }
serde_json = { workspace = true, optional = true }
wat = { workspace = true, optional = true }

Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ log = { workspace = true }
tempfile = "3.0"
wasm-mutate = { workspace = true }
wasm-smith = { workspace = true, features = ['component-model', 'wasmparser'] }
wasmparser = { workspace = true, features = ['features'] }
wasmparser = { workspace = true, features = ['std', 'features'] }
wasmprinter = { workspace = true, features = ['component-model'] }
wasmtime = { workspace = true, optional = true }
wast = { workspace = true }
Expand Down
Loading