Skip to content

Commit c5bb925

Browse files
committed
Add rustversion dependency to meson build
1 parent 5db0535 commit c5bb925

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

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

third-party/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Must be sorted topologically, not alphabetically.
22
third_party = {
3+
'rustversion': subproject('rustversion').get_variable('dep'),
34
'unicode_ident': subproject('unicode-ident').get_variable('dep'),
45
'proc-macro2': subproject('proc-macro2').get_variable('dep'),
56
'quote': subproject('quote').get_variable('dep'),

tools/meson/buildscript_run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def main():
7373
cargo_rustc_cfg_match = cargo_rustc_cfg_pattern.match(line)
7474
if cargo_rustc_cfg_match:
7575
flags += "--cfg={}\n".format(cargo_rustc_cfg_match.group(1))
76+
flags += "--env-set=OUT_DIR={}\n".format(os.path.abspath(args.out_dir))
7677
args.rustc_args.write(flags)
7778

7879

0 commit comments

Comments
 (0)