Skip to content

Migrate to Rust 2024 Edition #1101

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Migrate to Rust 2024 Edition #1101

wants to merge 3 commits into from

Conversation

dherman
Copy link
Collaborator

@dherman dherman commented May 5, 2025

This PR upgrades Neon's two crates (neon and neon-macros) to Rust 2024 Edition.

Details:

- unsafe functions now mark any unsafe operations explicitly
- upgrade linkme to get fix for 2024 Edition (dtolnay/linkme#101)
- tweak internal generate! macro for a mysterious backwards-incompatibility in macro_rules! expansion behavior
Copy link

github-actions bot commented May 5, 2025

🐰 Bencher Report

Branchedition-2024
Testbedubuntu-latest

🚨 2 Alerts

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Lower Boundary
(Limit %)
Upper Boundary
(Limit %)
auto-exported-noopLatency
nanoseconds (ns)
📈 plot
🚷 threshold
🚨 alert (🔔)
27.91 ns
(-20.85%)Baseline: 35.26 ns
31.74 ns
(113.71%)

70.53 ns
(39.57%)
auto-exported-noopThroughput
operations / second (ops/s)
📈 plot
🚷 threshold
🚨 alert (🔔)
35,833,736.70 ops/s
(+22.14%)Baseline: 29,337,831.58 ops/s
0.00 ops/s
(0.00%)
32,271,614.74 ops/s
(111.04%)

Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Lower Boundary
nanoseconds (ns)
(Limit %)
Upper Boundary
nanoseconds (ns)
(Limit %)
ThroughputBenchmark Result
operations / second (ops/s)
(Result Δ%)
Lower Boundary
operations / second (ops/s)
(Limit %)
Upper Boundary
operations / second (ops/s)
(Limit %)
JsFunction::bind📈 view plot
🚷 view threshold
211.34 ns
(-0.47%)Baseline: 212.33 ns
191.10 ns
(90.42%)
424.66 ns
(49.77%)
📈 view plot
🚷 view threshold
4,731,855.32 ops/s
(+0.53%)Baseline: 4,706,741.91 ops/s
0.00 ops/s
(0.00%)
5,177,416.10 ops/s
(91.39%)
JsFunction::call📈 view plot
🚷 view threshold
221.51 ns
(-0.32%)Baseline: 222.22 ns
200.00 ns
(90.29%)
444.45 ns
(49.84%)
📈 view plot
🚷 view threshold
4,518,159.13 ops/s
(+0.64%)Baseline: 4,489,230.90 ops/s
0.00 ops/s
(0.00%)
4,938,153.99 ops/s
(91.49%)
JsFunction::call_with📈 view plot
🚷 view threshold
219.13 ns
(+3.28%)Baseline: 212.16 ns
190.94 ns
(87.14%)
424.32 ns
(51.64%)
📈 view plot
🚷 view threshold
4,560,157.58 ops/s
(-3.09%)Baseline: 4,705,442.17 ops/s
0.00 ops/s
(0.00%)
5,175,986.39 ops/s
(88.10%)
auto-exported-noop📈 view plot
🚷 view threshold
🚨 view alert (🔔)
27.91 ns
(-20.85%)Baseline: 35.26 ns
31.74 ns
(113.71%)

70.53 ns
(39.57%)
📈 view plot
🚷 view threshold
🚨 view alert (🔔)
35,833,736.70 ops/s
(+22.14%)Baseline: 29,337,831.58 ops/s
0.00 ops/s
(0.00%)
32,271,614.74 ops/s
(111.04%)

hello-world📈 view plot
🚷 view threshold
58.12 ns
(+0.58%)Baseline: 57.78 ns
52.00 ns
(89.48%)
115.56 ns
(50.29%)
📈 view plot
🚷 view threshold
16,910,423.12 ops/s
(-1.67%)Baseline: 17,198,160.04 ops/s
0.00 ops/s
(0.00%)
18,917,976.04 ops/s
(89.39%)
manually-exported-noop📈 view plot
🚷 view threshold
28.00 ns
(-2.39%)Baseline: 28.69 ns
25.82 ns
(92.20%)
57.38 ns
(48.81%)
📈 view plot
🚷 view threshold
35,728,080.92 ops/s
(+2.60%)Baseline: 34,823,720.66 ops/s
0.00 ops/s
(0.00%)
38,306,092.73 ops/s
(93.27%)
🐰 View full continuous benchmarking report in Bencher

Copy link

codecov bot commented May 5, 2025

Codecov Report

Attention: Patch coverage is 87.55365% with 87 lines in your changes missing coverage. Please review.

Project coverage is 83.78%. Comparing base (12a7954) to head (e4c7856).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
crates/neon/src/sys/call.rs 65.11% 15 Missing ⚠️
crates/neon/src/sys/no_panic.rs 83.33% 11 Missing and 1 partial ⚠️
crates/neon/src/context/internal.rs 35.29% 9 Missing and 2 partials ⚠️
crates/neon/src/sys/async_work.rs 86.20% 7 Missing and 1 partial ⚠️
crates/neon/src/sys/error.rs 82.22% 8 Missing ⚠️
crates/neon/src/sys/object.rs 80.95% 8 Missing ⚠️
crates/neon/src/sys/bindings/mod.rs 56.25% 7 Missing ⚠️
crates/neon/src/sys/bindings/functions.rs 75.00% 3 Missing and 1 partial ⚠️
crates/neon/src/sys/buffer.rs 86.20% 3 Missing and 1 partial ⚠️
crates/neon/src/sys/fun.rs 93.44% 4 Missing ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1101      +/-   ##
==========================================
+ Coverage   83.42%   83.78%   +0.35%     
==========================================
  Files          74       74              
  Lines        5546     5673     +127     
  Branches     5546     5673     +127     
==========================================
+ Hits         4627     4753     +126     
- Misses        806      817      +11     
+ Partials      113      103      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dherman dherman marked this pull request as ready for review May 5, 2025 17:04
@kjvalencik kjvalencik requested a review from Copilot May 23, 2025 21:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the Neon crates to the Rust 2024 Edition by explicitly marking unsafe operations, updating dependencies, and adjusting macro behavior for backwards-compatibility.

  • Wraps all FFI calls in explicit unsafe { … } blocks.
  • Refactors generate! macro into impl_napi_wrapper! and handles optional return types.
  • Bumps crate edition to 2024 and upgrades linkme.

Reviewed Changes

Copilot reviewed 58 out of 58 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/neon/Cargo.toml Updated to Rust 2024 Edition and bumped linkme.
crates/neon/src/sys/call.rs Added explicit unsafe blocks around N-API calls.
crates/neon/src/context/internal.rs Changed module registration attribute.
(other sys/*.rs files) Wrapped FFI invocations in unsafe blocks.
(various src/*.rs files) Reordered imports and moved unsafe calls into blocks.
Comments suppressed due to low confidence (2)

crates/neon/src/sys/call.rs:44

  • target is a MaybeUninit<Local> and does not have an is_null() method. You need to call target.assume_init().is_null() after initialization to check the pointer correctly.
!target.is_null()

crates/neon/src/context/internal.rs:79

  • The attribute #[unsafe(no_mangle)] is invalid. Replace it with #[no_mangle] and keep the unsafe extern "C" on the function signature.
#[unsafe(no_mangle)]

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