From 43f24060f3e0065b44b1909d88bcc8e2882e9e5e Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 21 Jun 2023 12:02:06 -0700 Subject: modules/rust: Add a `link_with` kwarg to the test method This was requested by Mesa, where a bunch of `declare_dependency` objects are being created as a workaround for the lack of this keyword --- docs/markdown/Rust-module.md | 5 ++++- docs/markdown/snippets/rust_test_link_with.md | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 docs/markdown/snippets/rust_test_link_with.md (limited to 'docs/markdown') diff --git a/docs/markdown/Rust-module.md b/docs/markdown/Rust-module.md index 7617dbb..512c4ec 100644 --- a/docs/markdown/Rust-module.md +++ b/docs/markdown/Rust-module.md @@ -18,7 +18,7 @@ like Meson, rather than Meson work more like rust. ## Functions -### test(name: string, target: library | executable, dependencies: []Dependency) +### test(name: string, target: library | executable, dependencies: []Dependency, link_with: []targets) This function creates a new rust unittest target from an existing rust based target, which may be a library or executable. It does this by @@ -33,6 +33,9 @@ that automatically. Additional, test only dependencies may be passed via the dependencies argument. +*(since 1.2.0)* the link_with argument can be used to pass additional build +targets to link with + ### bindgen(*, input: string | BuildTarget | [](string | BuildTarget), output: string, include_directories: [](include_directories | string), c_args: []string, args: []string, dependencies: []Dependency) This function wraps bindgen to simplify creating rust bindings around C diff --git a/docs/markdown/snippets/rust_test_link_with.md b/docs/markdown/snippets/rust_test_link_with.md new file mode 100644 index 0000000..9c2b7d6 --- /dev/null +++ b/docs/markdown/snippets/rust_test_link_with.md @@ -0,0 +1,4 @@ +## Add a `link_with` keyword to `rust.test()` + +This can already be be worked around by creating `declare_dependency()` objects +to pass to the `dependencies` keyword, but this cuts out the middle man. -- cgit v1.1 From c5b16ab8b957d53b75c73bb24144a4f61c86234d Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 21 Jun 2023 12:15:07 -0700 Subject: modules/rust: Add a machine file property for extra clang args with bindgen It's currently impossible to inject extra clang arguments when using bindgen, which is problematic when cross compiling since you may need critical arguments like `--target=...`. Because such arguments must be passed after the `--` it's impossible to inject them currently without going to something like a wrapper script. Fixes: #11805 --- docs/markdown/Machine-files.md | 2 ++ docs/markdown/Rust-module.md | 9 ++++++++- docs/markdown/snippets/rust_extra_clang_bindgen_arguments.md | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 docs/markdown/snippets/rust_extra_clang_bindgen_arguments.md (limited to 'docs/markdown') diff --git a/docs/markdown/Machine-files.md b/docs/markdown/Machine-files.md index ecdb8b4..9e4b0c2 100644 --- a/docs/markdown/Machine-files.md +++ b/docs/markdown/Machine-files.md @@ -237,6 +237,8 @@ section. subprojects. This setting has no effect if the `exe_wrapper` was not specified. The default value is `true`. (*new in 0.56.0*) - `java_home` is an absolute path pointing to the root of a Java installation. +- `bindgen_clang_arguments` an array of extra arguments to pass to clang when + calling bindgen ### CMake variables diff --git a/docs/markdown/Rust-module.md b/docs/markdown/Rust-module.md index 512c4ec..30a6345 100644 --- a/docs/markdown/Rust-module.md +++ b/docs/markdown/Rust-module.md @@ -86,10 +86,17 @@ r1 = rust.bindgen( ) ``` - *Since 1.1.0* Meson will synchronize assertions for Rust and C/C++ when the `b_ndebug` option is set (via `-DNDEBUG` for C/C++, and `-C debug-assertions=on` for Rust), and will pass `-DNDEBUG` as an extra argument to clang. This allows for reliable wrapping of `-DNDEBUG` controlled behavior with `#[cfg(debug_asserions)]` and or `cfg!()`. Before 1.1.0, assertions for Rust were never turned on by Meson. + +*Since 1.2.0* Additional arguments to pass to clang may be specified in a +*machine file in the properties section: + +```ini +[properties] +bindgen_clang_arguments = ['--target', 'x86_64-linux-gnu'] +``` diff --git a/docs/markdown/snippets/rust_extra_clang_bindgen_arguments.md b/docs/markdown/snippets/rust_extra_clang_bindgen_arguments.md new file mode 100644 index 0000000..71268d4 --- /dev/null +++ b/docs/markdown/snippets/rust_extra_clang_bindgen_arguments.md @@ -0,0 +1,8 @@ +## A machine file may be used to pass extra arguments to clang in a bindgen call + +Because of the way that bindgen proxies arguments to clang the only choice to +add extra arguments currently is to wrap bindgen in a script, since the +arguments must come after a `--`. This is inelegant, and not very portable. Now +a `bindgen_clang_arguments` field may be placed in the machine file for the host +machine, and these arguments will be added to every bindgen call for clang. This +is intended to be useful for things like injecting `--target` arguments. -- cgit v1.1 From 5d16bd5308f0edd9d53b82ff6a961241c7188423 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 22 Jun 2023 09:56:11 -0700 Subject: modules/rust: Add a keyword argument to pass extra args to the rust compiler This may be necessary to, for example, stop rustc complaining about unused functions --- docs/markdown/Rust-module.md | 4 +++- docs/markdown/snippets/rust_bindegen_extra_args.md | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 docs/markdown/snippets/rust_bindegen_extra_args.md (limited to 'docs/markdown') diff --git a/docs/markdown/Rust-module.md b/docs/markdown/Rust-module.md index 30a6345..d3891bf 100644 --- a/docs/markdown/Rust-module.md +++ b/docs/markdown/Rust-module.md @@ -18,7 +18,7 @@ like Meson, rather than Meson work more like rust. ## Functions -### test(name: string, target: library | executable, dependencies: []Dependency, link_with: []targets) +### test(name: string, target: library | executable, dependencies: []Dependency, link_with: []targets, rust_args: []string) This function creates a new rust unittest target from an existing rust based target, which may be a library or executable. It does this by @@ -35,6 +35,8 @@ argument. *(since 1.2.0)* the link_with argument can be used to pass additional build targets to link with +*(since 1.2.0)* the `rust_args` keyword argument can be ussed to pass extra +arguments to the Rust compiler. ### bindgen(*, input: string | BuildTarget | [](string | BuildTarget), output: string, include_directories: [](include_directories | string), c_args: []string, args: []string, dependencies: []Dependency) diff --git a/docs/markdown/snippets/rust_bindegen_extra_args.md b/docs/markdown/snippets/rust_bindegen_extra_args.md new file mode 100644 index 0000000..209d0bc --- /dev/null +++ b/docs/markdown/snippets/rust_bindegen_extra_args.md @@ -0,0 +1,3 @@ +## rust.bindgen allows passing extra arguments to rustc + +This may be necessary to pass extra `cfg`s or to change warning levels. -- cgit v1.1