Skip to content

fix: move cdylib to separate float-wasm crate#171

Closed
JuaniRios wants to merge 1 commit intorainlanguage:base/npm-v0.0.0-alpha.42from
JuaniRios:fix/remove-cdylib-from-float-crate
Closed

fix: move cdylib to separate float-wasm crate#171
JuaniRios wants to merge 1 commit intorainlanguage:base/npm-v0.0.0-alpha.42from
JuaniRios:fix/remove-cdylib-from-float-crate

Conversation

@JuaniRios
Copy link

@JuaniRios JuaniRios commented Mar 17, 2026

Summary

  • Removes cdylib from rain-math-float's crate-type, making it rlib-only
  • Introduces a new rain-math-float-wasm crate (crates/float-wasm) that re-exports rain-math-float as a cdylib
  • This avoids output filename collisions that cause duplicate dependency compilation in downstream consumers

Test plan

  • Verify cargo build succeeds for the workspace
  • Verify WASM builds still work via rain-math-float-wasm
  • Confirm downstream crates no longer see duplicate compilation of rain-math-float

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Refactor
    • Reorganized library structure to provide dedicated WebAssembly support through a new wrapper module.
    • Updated core library configuration for improved modularity and separation of concerns.

The `cdylib` crate-type on `rain-math-float` causes Cargo to produce
output artifacts with colliding filenames (rlib and cdylib both generate
`librain_math_float.*`). On Linux, this results in `alloy_primitives`
being compiled as two separate crate instances, causing type mismatches
for any downstream crate that imports both `alloy_primitives` and
`rain_math_float`:

    expected `FixedBytes<32>`, found a different `FixedBytes<32>`
    note: two different versions of crate `alloy_primitives` are being used

See: rust-lang/cargo#6313

The fix moves `cdylib` to a dedicated `rain-math-float-wasm` wrapper
crate (`crates/float-wasm`), keeping the core library as `rlib`-only.
WASM consumers should depend on `rain-math-float-wasm` instead. Native
consumers are unaffected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

Walkthrough

A new WASM wrapper crate is introduced that re-exports all public items from the core rain_math_float library. The core library's crate-type is modified to remove cdylib support, delegating WASM artifact generation solely to the wrapper crate to prevent filename collisions.

Changes

Cohort / File(s) Summary
New WASM Wrapper Crate
crates/float-wasm/Cargo.toml, crates/float-wasm/src/lib.rs
New dedicated WASM wrapper crate with cdylib configuration. Re-exports all public items from the core rain_math_float library via wildcard use statement.
Core Library Configuration
crates/float/Cargo.toml
Removed cdylib crate-type from core library, restricting it to rlib only. WASM artifact generation is now handled exclusively by the separate wrapper crate.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and accurately summarizes the main change: moving the cdylib crate type from the float crate to a new separate float-wasm wrapper crate.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/float-wasm/Cargo.toml`:
- Around line 1-12: The crate's package name rain-math-float-wasm produces an
artifact rain_math_float_wasm.wasm but the build script scripts/build.js expects
rain_math_float.wasm; to fix, add a name override under [lib] (e.g., name =
"rain_math_float") in this Cargo.toml so the generated WASM artifact matches the
wasm-bindgen invocations, or alternatively update the wasm-bindgen calls in
scripts/build.js to reference rain_math_float_wasm.wasm; modify the Cargo.toml
[lib] block (or the wasm-bindgen lines in scripts/build.js) accordingly to make
the artifact name consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ed05a43b-ac24-442e-8612-6e1fa26e6a77

📥 Commits

Reviewing files that changed from the base of the PR and between 50aa96e and 83033e2.

📒 Files selected for processing (3)
  • crates/float-wasm/Cargo.toml
  • crates/float-wasm/src/lib.rs
  • crates/float/Cargo.toml

Comment on lines +1 to +12
[package]
name = "rain-math-float-wasm"
version = "0.1.0"
edition = "2021"
license = "LicenseRef-DCL-1.0"
homepage = "https://github.com/rainlanguage/rain.math.float"

[lib]
crate-type = ["cdylib"]

[dependencies]
rain-math-float = { path = "../float" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the hardcoded artifact paths in build.js
echo "=== Checking build.js for hardcoded artifact paths ==="
rg -n "rain_math_float" scripts/build.js

Repository: rainlanguage/rain.math.float

Length of output: 394


Build script incompatibility: artifact name mismatch.

The package name rain-math-float-wasm will produce a WASM artifact named rain_math_float_wasm.wasm, but the build script (scripts/build.js) hardcodes the artifact name as rain_math_float.wasm:

wasm-bindgen --target nodejs ./target/wasm32-unknown-unknown/release/rain_math_float.wasm ...
wasm-bindgen --target web ./target/wasm32-unknown-unknown/release/rain_math_float.wasm ...

This mismatch will cause the WASM build to fail.

Fix options:

  1. Add name = "rain_math_float" under [lib] to preserve the original artifact name:
 [lib]
 crate-type = ["cdylib"]
+name = "rain_math_float"
  1. Or update scripts/build.js to reference rain_math_float_wasm.wasm.

Option 1 is recommended.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/float-wasm/Cargo.toml` around lines 1 - 12, The crate's package name
rain-math-float-wasm produces an artifact rain_math_float_wasm.wasm but the
build script scripts/build.js expects rain_math_float.wasm; to fix, add a name
override under [lib] (e.g., name = "rain_math_float") in this Cargo.toml so the
generated WASM artifact matches the wasm-bindgen invocations, or alternatively
update the wasm-bindgen calls in scripts/build.js to reference
rain_math_float_wasm.wasm; modify the Cargo.toml [lib] block (or the
wasm-bindgen lines in scripts/build.js) accordingly to make the artifact name
consistent.

@JuaniRios JuaniRios changed the base branch from main to base/npm-v0.0.0-alpha.42 March 17, 2026 18:52
@JuaniRios JuaniRios closed this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant