diff options
| -rw-r--r-- | docs/markdown/Rust.md | 8 | ||||
| -rw-r--r-- | mesonbuild/backend/ninjabackend.py | 3 | ||||
| -rw-r--r-- | test cases/rust/30 both machines/lib.rs | 3 | ||||
| -rw-r--r-- | test cases/rust/30 both machines/meson.build | 36 | ||||
| -rw-r--r-- | test cases/rust/30 both machines/test.rs | 5 |
5 files changed, 54 insertions, 1 deletions
diff --git a/docs/markdown/Rust.md b/docs/markdown/Rust.md index 452dad6e6..67bbdec5b 100644 --- a/docs/markdown/Rust.md +++ b/docs/markdown/Rust.md @@ -98,3 +98,11 @@ target is a proc macro or dylib, or it depends on a dylib, in which case [`-C prefer-dynamic`](https://doc.rust-lang.org/rustc/codegen-options/index.html#prefer-dynamic) will be passed to the Rust compiler, and the standard libraries will be dynamically linked. + +## Multiple targets for the same crate name + +For library targets that have `rust_abi: 'rust'`, the crate name is derived from the +target name. First, dashes, spaces and dots are replaced with underscores. Second, +*since 1.10.0* anything after the first `+` is dropped. This allows creating multiple +targets for the same crate name, for example when the same crate is built multiple +times with different features, or for both the build and the host machine. diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 5486b089b..13f4cdc81 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1950,8 +1950,9 @@ class NinjaBackend(backends.Backend): @staticmethod def _get_rust_crate_name(target_name: str) -> str: # Rustc replaces - with _. spaces or dots are not allowed, so we replace them with underscores + # Also +SUFFIX is dropped, which can be used to distinguish host from build crates crate_name = target_name.replace('-', '_').replace(' ', '_').replace('.', '_') - return crate_name + return crate_name.split('+', 1)[0] @staticmethod def _get_rust_dependency_name(target: build.BuildTarget, dependency: LibTypes) -> str: diff --git a/test cases/rust/30 both machines/lib.rs b/test cases/rust/30 both machines/lib.rs new file mode 100644 index 000000000..432593368 --- /dev/null +++ b/test cases/rust/30 both machines/lib.rs @@ -0,0 +1,3 @@ +pub fn answer() -> u32 { + 42 +} diff --git a/test cases/rust/30 both machines/meson.build b/test cases/rust/30 both machines/meson.build new file mode 100644 index 000000000..511518a7b --- /dev/null +++ b/test cases/rust/30 both machines/meson.build @@ -0,0 +1,36 @@ +project( + 'testproj', + 'rust', + version : '0.1', + meson_version : '>= 1.9.0', + default_options : ['rust_std=2021'], +) + +lib_host = static_library( + 'lib', + 'lib.rs', + rust_abi: 'rust' +) + +lib_build = static_library( + 'lib+build', + 'lib.rs', + rust_abi: 'rust', + native: true, +) + +exe_host = executable( + 'test-host', + 'test.rs', + link_with: lib_host, +) + +exe_build = executable( + 'test-build', + 'test.rs', + link_with: lib_build, + native: true, +) + +test('host', exe_host) +test('build', exe_build) diff --git a/test cases/rust/30 both machines/test.rs b/test cases/rust/30 both machines/test.rs new file mode 100644 index 000000000..c9679d452 --- /dev/null +++ b/test cases/rust/30 both machines/test.rs @@ -0,0 +1,5 @@ +use lib::answer; + +fn main() { + println!("The answer is {}.\n", answer()); +} |
