Skip to content

Commit 7e032e9

Browse files
authored
Merge pull request #1389 from dtolnay/meson
Meson, with handwritten meson.build for deps
2 parents 9f8a272 + 38e6c54 commit 7e032e9

32 files changed

+582
-0
lines changed

.github/workflows/ci.yml

+17
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,23 @@ jobs:
116116
run: git diff --exit-code
117117
if: matrix.os == 'ubuntu' || matrix.os == 'macos'
118118

119+
meson:
120+
name: Meson
121+
runs-on: ubuntu-latest
122+
if: github.event_name != 'pull_request'
123+
timeout-minutes: 45
124+
steps:
125+
- uses: actions/checkout@v4
126+
- uses: actions/checkout@v4
127+
with:
128+
repository: mesonbuild/meson
129+
path: meson
130+
- run: sudo apt-get install lld ninja-build
131+
- run: meson/meson.py setup --native-file=tools/meson/native.ini build
132+
- run: meson/meson.py compile -C build
133+
- run: build/demo/demo
134+
- run: meson/meson.py test -C build
135+
119136
minimal:
120137
name: Minimal versions
121138
needs: pre_ci

demo/meson.build

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
demo_bridge = static_library(
2+
'demo_bridge',
3+
implicit_include_directories: false,
4+
include_directories: project_root,
5+
sources: cxxbridge_generator.process(
6+
files('src/main.rs'),
7+
preserve_path_from: meson.project_source_root(),
8+
),
9+
)
10+
11+
demo_blobstore = static_library(
12+
'demo_blobstore',
13+
implicit_include_directories: false,
14+
include_directories: [demo_bridge.private_dir_include(), project_root],
15+
link_with: demo_bridge,
16+
sources: [files('src/blobstore.cc'), cxx_header],
17+
)
18+
19+
executable(
20+
'demo',
21+
link_with: [demo_blobstore, cxx_library],
22+
sources: files('src/main.rs'),
23+
)

meson.build

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
project(
2+
'cxx',
3+
default_options: ['rust_std=2021'],
4+
license: 'MIT OR Apache-2.0',
5+
license_files: ['LICENSE-APACHE', 'LICENSE-MIT'],
6+
meson_version: '>= 1.3.0',
7+
)
8+
9+
add_languages('rust', native: true)
10+
add_languages('rust', 'cpp', native: false)
11+
12+
subdir('tools/meson')
13+
subdir('third-party')
14+
15+
rust = import('rust')
16+
17+
project_root = include_directories('.')
18+
19+
cxx_core = static_library(
20+
'cxx_core',
21+
implicit_include_directories: false,
22+
sources: files('src/cxx.cc'),
23+
)
24+
25+
cxxbridge_macro = rust.proc_macro(
26+
'cxxbridge_macro',
27+
dependencies: [
28+
third_party['proc-macro2'],
29+
third_party['quote'],
30+
third_party['syn'],
31+
],
32+
sources: files('macro/src/lib.rs'),
33+
)
34+
35+
cxx_library = static_library(
36+
'cxx',
37+
link_with: [cxx_core, cxxbridge_macro],
38+
rust_args: [
39+
'--cfg=feature="alloc"',
40+
'--cfg=feature="default"',
41+
'--cfg=feature="std"',
42+
],
43+
sources: files('src/lib.rs'),
44+
)
45+
46+
cxxbridge_cmd = executable(
47+
'cxxbridge',
48+
dependencies: [
49+
third_party['clap'],
50+
third_party['codespan-reporting'],
51+
third_party['proc-macro2'],
52+
third_party['quote'],
53+
third_party['syn'],
54+
],
55+
native: true,
56+
sources: files('gen/cmd/src/main.rs'),
57+
)
58+
59+
cxxbridge_generator = generator(
60+
cxxbridge_cmd,
61+
arguments: ['@INPUT@', '-o', '@OUTPUT0@', '-o', '@OUTPUT1@'],
62+
63+
)
64+
65+
cxx_header = custom_target(
66+
'cxx_header',
67+
command: ['bash', '-c', 'mkdir -p rust; cp @INPUT@ rust'],
68+
input: files('include/cxx.h'),
69+
output: 'rust',
70+
)
71+
72+
subdir('demo')
73+
subdir('tests')

subprojects/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
!/.gitignore
3+
!/packagefiles/
4+
!/*.wrap

subprojects/anstyle.wrap

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-file]
2+
directory = anstyle-1.0.9
3+
source_url = https://static.crates.io/crates/anstyle/1.0.9/download
4+
source_filename = anstyle-1.0.9.tar.gz
5+
source_hash = 8365de52b16c035ff4fcafe0092ba9390540e3e352870ac09933bebcaa2c8c56
6+
patch_directory = anstyle

subprojects/clap.wrap

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-file]
2+
directory = clap-4.5.20
3+
source_url = https://static.crates.io/crates/clap/4.5.20/download
4+
source_filename = clap-4.5.20.tar.gz
5+
source_hash = b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8
6+
patch_directory = clap

subprojects/clap_builder.wrap

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-file]
2+
directory = clap_builder-4.5.20
3+
source_url = https://static.crates.io/crates/clap_builder/4.5.20/download
4+
source_filename = clap_builder-4.5.20.tar.gz
5+
source_hash = 19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54
6+
patch_directory = clap_builder

subprojects/clap_lex.wrap

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-file]
2+
directory = clap_lex-0.7.2
3+
source_url = https://static.crates.io/crates/clap_lex/0.7.2/download
4+
source_filename = clap_lex-0.7.2.tar.gz
5+
source_hash = 1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97
6+
patch_directory = clap_lex

subprojects/codespan-reporting.wrap

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-file]
2+
directory = codespan-reporting-0.11.1
3+
source_url = https://static.crates.io/crates/codespan-reporting/0.11.1/download
4+
source_filename = codespan-reporting-0.11.1.tar.gz
5+
source_hash = 3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e
6+
patch_directory = codespan-reporting
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
project(
2+
'anstyle',
3+
'rust',
4+
default_options: ['rust_std=2021'],
5+
license: 'MIT OR Apache-2.0',
6+
version: '1.0.9',
7+
)
8+
9+
lib = static_library(
10+
'anstyle',
11+
native: true,
12+
rust_args: ['--cfg=feature="default"', '--cfg=feature="std"'],
13+
sources: files('src/lib.rs'),
14+
)
15+
16+
dep = declare_dependency(link_with: lib)
17+
meson.override_dependency('anstyle', dep)
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
project(
2+
'clap',
3+
'rust',
4+
default_options: ['rust_std=2021'],
5+
license: 'MIT OR Apache-2.0',
6+
version: '4.5.20',
7+
)
8+
9+
lib = static_library(
10+
'clap',
11+
dependencies: [dependency('clap_builder', version: ['= 4.5.20'])],
12+
native: true,
13+
rust_args: [
14+
'--cfg=feature="error-context"',
15+
'--cfg=feature="help"',
16+
'--cfg=feature="std"',
17+
'--cfg=feature="usage"',
18+
],
19+
sources: files('src/lib.rs'),
20+
)
21+
22+
dep = declare_dependency(link_with: lib)
23+
meson.override_dependency('clap', dep)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
project(
2+
'clap_builder',
3+
'rust',
4+
default_options: ['rust_std=2021'],
5+
license: 'MIT OR Apache-2.0',
6+
version: '4.5.20',
7+
)
8+
9+
lib = static_library(
10+
'clap_builder',
11+
dependencies: [
12+
dependency('anstyle', version: ['>= 1.0.8', '< 2']),
13+
dependency('clap_lex', version: ['>= 0.7.0', '< 0.8']),
14+
],
15+
native: true,
16+
rust_args: [
17+
'--cfg=feature="error-context"',
18+
'--cfg=feature="help"',
19+
'--cfg=feature="std"',
20+
'--cfg=feature="usage"',
21+
],
22+
sources: files('src/lib.rs'),
23+
)
24+
25+
dep = declare_dependency(link_with: lib)
26+
meson.override_dependency('clap_builder', dep)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
project(
2+
'clap_lex',
3+
'rust',
4+
default_options: ['rust_std=2021'],
5+
license: 'MIT OR Apache-2.0',
6+
version: '0.7.2',
7+
)
8+
9+
lib = static_library('clap_lex', native: true, sources: files('src/lib.rs'))
10+
11+
dep = declare_dependency(link_with: lib)
12+
meson.override_dependency('clap_lex', dep)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
project(
2+
'codespan-reporting',
3+
'rust',
4+
default_options: ['rust_std=2018'],
5+
license: 'Apache-2.0',
6+
version: '0.11.1',
7+
)
8+
9+
lib = static_library(
10+
'codespan_reporting',
11+
dependencies: [
12+
dependency('termcolor', version: ['>= 1', '< 2']),
13+
dependency('unicode-width', version: ['>= 0.1', '< 0.2']),
14+
],
15+
native: true,
16+
sources: files('src/lib.rs'),
17+
)
18+
19+
dep = declare_dependency(link_with: lib)
20+
meson.override_dependency('codespan-reporting', dep)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
project(
2+
'proc-macro2',
3+
'rust',
4+
default_options: ['rust_std=2021'],
5+
license: 'MIT OR Apache-2.0',
6+
version: '1.0.89',
7+
)
8+
9+
build = executable(
10+
'build_script',
11+
native: true,
12+
rust_args: [
13+
'--cfg=feature="default"',
14+
'--cfg=feature="proc-macro"',
15+
'--cfg=feature="span-locations"',
16+
],
17+
sources: files('build.rs'),
18+
)
19+
20+
rustc_args = custom_target(
21+
command: [
22+
find_program('python3'),
23+
'@SOURCE_ROOT@/tools/meson/buildscript_run.py',
24+
'--buildscript',
25+
build,
26+
'--manifest-dir',
27+
'@CURRENT_SOURCE_DIR@',
28+
'--rustc-wrapper',
29+
'@BUILD_ROOT@/tools/meson/rustc_wrapper.sh',
30+
'--out-dir',
31+
'@PRIVATE_DIR@',
32+
'--rustc-args',
33+
'@OUTPUT@',
34+
],
35+
# Hack: any extension other than .rs causes a failure "ERROR: Rust target
36+
# proc_macro2 contains a non-rust source file" below, and forces the use of
37+
# `structured_sources` which would mean listing out every source file in the
38+
# crate, instead of just the crate root lib.rs.
39+
output: 'rustc_args.out.rs',
40+
)
41+
42+
lib = static_library(
43+
'proc_macro2',
44+
dependencies: [dependency('unicode-ident', version: ['>= 1', '< 2'])],
45+
native: true,
46+
rust_args: [
47+
'--cfg=feature="default"',
48+
'--cfg=feature="proc-macro"',
49+
'--cfg=feature="span-locations"',
50+
'@' + rustc_args.full_path(),
51+
],
52+
sources: [files('src/lib.rs'), rustc_args],
53+
)
54+
55+
dep = declare_dependency(link_with: lib)
56+
meson.override_dependency('proc-macro2', dep)
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
project(
2+
'quote',
3+
'rust',
4+
default_options: ['rust_std=2018'],
5+
license: 'MIT OR Apache-2.0',
6+
version: '1.0.37',
7+
)
8+
9+
lib = static_library(
10+
'quote',
11+
dependencies: [dependency('proc-macro2', version: ['>= 1.0.80', '< 2'])],
12+
native: true,
13+
rust_args: ['--cfg=feature="default"', '--cfg=feature="proc-macro"'],
14+
sources: files('src/lib.rs'),
15+
)
16+
17+
dep = declare_dependency(link_with: lib)
18+
meson.override_dependency('quote', dep)
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
project(
2+
'syn',
3+
'rust',
4+
default_options: ['rust_std=2021'],
5+
license: 'MIT OR Apache-2.0',
6+
version: '2.0.85',
7+
)
8+
9+
lib = static_library(
10+
'syn',
11+
dependencies: [
12+
dependency('proc-macro2', version: ['>= 1.0.83', '< 2']),
13+
dependency('quote', version: ['>= 1.0.35', '< 2']),
14+
dependency('unicode-ident', version: ['>= 1', '< 2']),
15+
],
16+
native: true,
17+
rust_args: [
18+
'--cfg=feature="clone-impls"',
19+
'--cfg=feature="default"',
20+
'--cfg=feature="derive"',
21+
'--cfg=feature="full"',
22+
'--cfg=feature="parsing"',
23+
'--cfg=feature="printing"',
24+
'--cfg=feature="proc-macro"',
25+
],
26+
sources: files('src/lib.rs'),
27+
)
28+
29+
dep = declare_dependency(link_with: lib)
30+
meson.override_dependency('syn', dep)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
project(
2+
'termcolor',
3+
'rust',
4+
default_options: ['rust_std=2018'],
5+
license: 'Unlicense OR MIT',
6+
version: '1.4.1',
7+
)
8+
9+
lib = static_library('termcolor', native: true, sources: files('src/lib.rs'))
10+
11+
dep = declare_dependency(link_with: lib)
12+
meson.override_dependency('termcolor', dep)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
project(
2+
'unicode-ident',
3+
'rust',
4+
default_options: ['rust_std=2018'],
5+
license: '(MIT OR Apache-2.0) AND Unicode-DFS-2016',
6+
version: '1.0.13',
7+
)
8+
9+
lib = static_library('unicode_ident', native: true, sources: files('src/lib.rs'))
10+
11+
dep = declare_dependency(link_with: lib)
12+
meson.override_dependency('unicode-ident', dep)

0 commit comments

Comments
 (0)