Skip to content

Commit 7c8ef12

Browse files
authored
Merge pull request #1395 from dtolnay/edition2024
Make generated code compatible with Rust 2024 edition
2 parents 13fc06b + f50438e commit 7c8ef12

File tree

19 files changed

+396
-52
lines changed

19 files changed

+396
-52
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
with:
129129
repository: mesonbuild/meson
130130
path: meson
131+
- uses: dtolnay/rust-toolchain@nightly
131132
- run: sudo apt-get install lld ninja-build
132133
- run: meson/meson.py setup --native-file=tools/meson/native.ini build
133134
- run: meson/meson.py compile -C build

BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ rust_library(
5858
deps = [
5959
"//third-party:proc-macro2",
6060
"//third-party:quote",
61+
"//third-party:rustversion",
6162
"//third-party:syn",
6263
],
6364
)

BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ rust_proc_macro(
5454
name = "cxxbridge-macro",
5555
srcs = glob(["macro/src/**/*.rs"]),
5656
edition = "2021",
57+
proc_macro_deps = [
58+
"@crates.io//:rustversion",
59+
],
5760
deps = [
5861
"@crates.io//:proc-macro2",
5962
"@crates.io//:quote",

MODULE.bazel.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

macro/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ experimental-enum-variants-from-header = ["clang-ast", "flate2", "memmap", "serd
2323
[dependencies]
2424
proc-macro2 = "1.0.74"
2525
quote = "1.0.35"
26+
rustversion = "1"
2627
syn = { version = "2.0.46", features = ["full"] }
2728

2829
# optional dependencies:

macro/src/expand.rs

Lines changed: 92 additions & 50 deletions
Large diffs are not rendered by default.

meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ add_project_arguments(
1616
language: 'cpp',
1717
)
1818

19+
add_global_arguments('-Zunstable-options', language: 'rust', native: true)
20+
1921
subdir('tools/meson')
2022
subdir('third-party')
2123

@@ -34,6 +36,7 @@ cxxbridge_macro = rust.proc_macro(
3436
dependencies: [
3537
third_party['proc-macro2'],
3638
third_party['quote'],
39+
third_party['rustversion'],
3740
third_party['syn'],
3841
],
3942
sources: files('macro/src/lib.rs'),
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
project(
2+
'rustversion',
3+
'rust',
4+
default_options: ['rust_std=2018'],
5+
license: 'MIT OR Apache-2.0',
6+
meson_version: '>= 1.3.0',
7+
version: '1.0.18',
8+
)
9+
10+
rust = import('rust')
11+
12+
build = executable(
13+
'build_script',
14+
native: true,
15+
sources: files('build/build.rs'),
16+
)
17+
18+
rustc_args = custom_target(
19+
command: [
20+
find_program('python3'),
21+
'@SOURCE_ROOT@/tools/meson/buildscript_run.py',
22+
'--buildscript',
23+
build,
24+
'--manifest-dir',
25+
'@CURRENT_SOURCE_DIR@',
26+
'--rustc-wrapper',
27+
'@BUILD_ROOT@/tools/meson/rustc_wrapper.sh',
28+
'--out-dir',
29+
'@PRIVATE_DIR@',
30+
'--rustc-args',
31+
'@OUTPUT@',
32+
],
33+
env: {'HOST': 'x86_64-unknown-linux-gnu'},
34+
# Hack: any extension other than .rs causes a failure "ERROR: Rust target
35+
# rustversion contains a non-rust source file" below, and forces the use of
36+
# `structured_sources` which would mean listing out every source file in the
37+
# crate, instead of just the crate root lib.rs.
38+
output: 'rustc_args.out.rs',
39+
)
40+
41+
lib = rust.proc_macro(
42+
'rustversion',
43+
rust_args: ['@' + rustc_args.full_path()],
44+
sources: [files('src/lib.rs'), rustc_args],
45+
)
46+
47+
dep = declare_dependency(link_with: lib)
48+
meson.override_dependency('rustversion', dep)

subprojects/rustversion.wrap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-file]
2+
directory = rustversion-1.0.18
3+
source_url = https://static.crates.io/crates/rustversion/1.0.18/download
4+
source_filename = rustversion-1.0.18.tar.gz
5+
source_hash = 0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248
6+
patch_directory = rustversion

tests/ffi/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![forbid(unsafe_op_in_unsafe_fn)]
21
#![allow(
32
clippy::boxed_local,
43
clippy::derive_partial_eq_without_eq,
@@ -15,6 +14,9 @@
1514
clippy::unnecessary_wraps,
1615
clippy::unused_self
1716
)]
17+
#![allow(unknown_lints)]
18+
#![warn(rust_2024_compatibility)]
19+
#![forbid(unsafe_op_in_unsafe_fn)]
1820

1921
pub mod cast;
2022
pub mod module;
@@ -456,13 +458,15 @@ fn r_return_box() -> Box<R> {
456458
}
457459

458460
fn r_return_unique_ptr() -> UniquePtr<ffi::C> {
461+
#[allow(missing_unsafe_on_extern)]
459462
extern "C" {
460463
fn cxx_test_suite_get_unique_ptr() -> *mut ffi::C;
461464
}
462465
unsafe { UniquePtr::from_raw(cxx_test_suite_get_unique_ptr()) }
463466
}
464467

465468
fn r_return_shared_ptr() -> SharedPtr<ffi::C> {
469+
#[allow(missing_unsafe_on_extern)]
466470
extern "C" {
467471
fn cxx_test_suite_get_shared_ptr(repr: *mut SharedPtr<ffi::C>);
468472
}
@@ -501,6 +505,7 @@ fn r_return_rust_string() -> String {
501505
}
502506

503507
fn r_return_unique_ptr_string() -> UniquePtr<CxxString> {
508+
#[allow(missing_unsafe_on_extern)]
504509
extern "C" {
505510
fn cxx_test_suite_get_unique_ptr_string() -> *mut CxxString;
506511
}

third-party/BUCK

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

third-party/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

third-party/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ clap = { version = "4", default-features = false, features = ["error-context", "
1212
codespan-reporting = "0.11.1"
1313
proc-macro2 = { version = "1.0.58", features = ["span-locations"] }
1414
quote = "1.0.4"
15+
rustversion = "1"
1516
scratch = "1"
1617
syn = { version = "2.0.1", features = ["full"] }

third-party/bazel/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)