Skip to content

Commit

Permalink
Add rustversion dependency to meson build
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 12, 2024
1 parent 5db0535 commit c5bb925
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ add_project_arguments(
language: 'cpp',
)

add_global_arguments('-Zunstable-options', language: 'rust', native: true)

subdir('tools/meson')
subdir('third-party')

Expand All @@ -34,6 +36,7 @@ cxxbridge_macro = rust.proc_macro(
dependencies: [
third_party['proc-macro2'],
third_party['quote'],
third_party['rustversion'],
third_party['syn'],
],
sources: files('macro/src/lib.rs'),
Expand Down
48 changes: 48 additions & 0 deletions subprojects/packagefiles/rustversion/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
project(
'rustversion',
'rust',
default_options: ['rust_std=2018'],
license: 'MIT OR Apache-2.0',
meson_version: '>= 1.3.0',
version: '1.0.18',
)

rust = import('rust')

build = executable(
'build_script',
native: true,
sources: files('build/build.rs'),
)

rustc_args = custom_target(
command: [
find_program('python3'),
'@SOURCE_ROOT@/tools/meson/buildscript_run.py',
'--buildscript',
build,
'--manifest-dir',
'@CURRENT_SOURCE_DIR@',
'--rustc-wrapper',
'@BUILD_ROOT@/tools/meson/rustc_wrapper.sh',
'--out-dir',
'@PRIVATE_DIR@',
'--rustc-args',
'@OUTPUT@',
],
env: {'HOST': 'x86_64-unknown-linux-gnu'},
# Hack: any extension other than .rs causes a failure "ERROR: Rust target
# rustversion contains a non-rust source file" below, and forces the use of
# `structured_sources` which would mean listing out every source file in the
# crate, instead of just the crate root lib.rs.
output: 'rustc_args.out.rs',
)

lib = rust.proc_macro(
'rustversion',
rust_args: ['@' + rustc_args.full_path()],
sources: [files('src/lib.rs'), rustc_args],
)

dep = declare_dependency(link_with: lib)
meson.override_dependency('rustversion', dep)
6 changes: 6 additions & 0 deletions subprojects/rustversion.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = rustversion-1.0.18
source_url = https://static.crates.io/crates/rustversion/1.0.18/download
source_filename = rustversion-1.0.18.tar.gz
source_hash = 0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248
patch_directory = rustversion
1 change: 1 addition & 0 deletions third-party/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Must be sorted topologically, not alphabetically.
third_party = {
'rustversion': subproject('rustversion').get_variable('dep'),
'unicode_ident': subproject('unicode-ident').get_variable('dep'),
'proc-macro2': subproject('proc-macro2').get_variable('dep'),
'quote': subproject('quote').get_variable('dep'),
Expand Down
1 change: 1 addition & 0 deletions tools/meson/buildscript_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def main():
cargo_rustc_cfg_match = cargo_rustc_cfg_pattern.match(line)
if cargo_rustc_cfg_match:
flags += "--cfg={}\n".format(cargo_rustc_cfg_match.group(1))
flags += "--env-set=OUT_DIR={}\n".format(os.path.abspath(args.out_dir))
args.rustc_args.write(flags)


Expand Down

0 comments on commit c5bb925

Please sign in to comment.