Fix wasm32-unknown-unknown target build#6278
Conversation
WalkthroughWorkspace Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
e3800b0 to
c0d426f
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/vm/Cargo.toml (1)
27-27: Critical: Removechrono/wasmbindfrom the feature definition.The
wasmbindfeature referenceschrono/wasmbind, but the workspace configuration forchrono(line 165 in rootCargo.toml) explicitly disables default features and only enables["clock", "oldtime", "std"]. Thewasmbindfeature is not included, so this will cause a build error when thewasmbindfeature is enabled.Apply this diff to fix the feature definition:
-wasmbind = ["rustpython-common/wasm_js", "chrono/wasmbind", "wasm-bindgen"] +wasmbind = ["rustpython-common/wasm_js", "wasm-bindgen"]
🧹 Nitpick comments (1)
wasm/wasm-unknown-test/src/lib.rs (1)
1-11: Consider renaming the exported function to avoid shadowing the imported module.The exported function
evalshares the same name as the importedevalmodule, which can be confusing when reading the code (e.g., line 8:eval::eval(...)).Consider renaming the exported function for clarity:
use rustpython_vm::{Interpreter, eval}; #[unsafe(no_mangle)] -pub unsafe extern "C" fn eval(s: *const u8, l: usize) -> u32 { +pub unsafe extern "C" fn python_eval(s: *const u8, l: usize) -> u32 { let src = std::slice::from_raw_parts(s, l); let src = std::str::from_utf8(src).unwrap(); Interpreter::without_stdlib(Default::default()).enter(|vm| { let res = eval::eval(vm, src, vm.new_scope_with_builtins(), "<string>").unwrap(); res.try_into_value(vm).unwrap() }) }Note: If external code depends on the
evalsymbol name, this change would be breaking.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
Cargo.toml(1 hunks)crates/vm/Cargo.toml(2 hunks)wasm/wasm-unknown-test/src/lib.rs(1 hunks)
🔇 Additional comments (3)
crates/vm/Cargo.toml (1)
49-49: LGTM: Dependency reorganization aligns with wasm32-unknown-unknown target support.The changes correctly:
- Simplify chrono to use workspace configuration
- Make wasm-bindgen optional and broaden its target condition to
cfg(target_arch = "wasm32")- Add getrandom specifically for
cfg(all(target_arch = "wasm32", target_os = "unknown"))This allows wasm32-unknown-unknown builds without wasm-bindgen while keeping it available for other wasm32 targets.
Also applies to: 151-155
Cargo.toml (1)
165-165: LGTM: Explicit chrono feature configuration improves wasm32-unknown-unknown compatibility.The change to explicitly disable default features and enable only
["clock", "oldtime", "std"]removes the implicitwasmbindfeature dependency, which aligns with the PR objective of removing wasm-bindgen requirements for the wasm32-unknown-unknown target.wasm/wasm-unknown-test/src/lib.rs (1)
3-3: The#[unsafe(no_mangle)]syntax is properly supported.The workspace
rust-versionis 1.89.0, which exceeds the 1.82 requirement for this attribute syntax. The code change correctly prevents the function symbol from being omitted in the WASM output.
|
|
@ShaharNaveh Then adding wasmbind feature to vm will not enable chrono/wasmbind. @coderabbitai is wrong about it |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 710 @youknowone You're absolutely correct, and I apologize for the error in the previous review comment. The In Cargo, workspace dependency configurations set a baseline of features, but individual crates can enable additional features on top of that baseline through their own feature definitions. In this case:
Thank you for the correction! |
c0d426f to
d6c72a5
Compare
d6c72a5 to
5d51df6
Compare
This pull request fixes
wasm32-unknown-unknowntarget build in the following 2 points._wbg_xxxfunctions through imports object to use WASM build output.#[unsafe(no_mangle)]line forwasm/wasm-unknown-test/src/lib.rsfile because the build without the line, doesn't includeevalfile in the build output. You can check it by runningcd wasm/wasm-unknown-test/; cargo build --target wasm32-unknown-unknown; wasm2wat target/wasm32-unknown-unknown/debug/wasm_unknown_test.wasm. There may be no$evalfunction if the line doesn't exist.Links
Summary by CodeRabbit