diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2023-07-13 09:28:59 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2023-07-15 12:22:30 -0700 |
commit | 76eba998504b4205ea04859ba4c26f4a609afd94 (patch) | |
tree | 1a08572c98073c7c2270b6fc092eac8e81517e13 /test cases/rust | |
parent | adaea4136fdbf24933f243400f7771128f74deed (diff) | |
download | meson-76eba998504b4205ea04859ba4c26f4a609afd94.zip meson-76eba998504b4205ea04859ba4c26f4a609afd94.tar.gz meson-76eba998504b4205ea04859ba4c26f4a609afd94.tar.bz2 |
rust: disable overflow-checks by default
These result in very large binaries when linked, and are not generally
useful. A user can turn them back on by passing `-C overflow-checks=yes`
manually via `-Drust_args` or the `RUSTFLAGS` environment variable
fixes: #11785
Diffstat (limited to 'test cases/rust')
-rw-r--r-- | test cases/rust/5 polyglot static/clib.c | 6 | ||||
-rw-r--r-- | test cases/rust/5 polyglot static/meson.build | 7 | ||||
-rwxr-xr-x | test cases/rust/5 polyglot static/overflow_size_checks.py | 29 | ||||
-rw-r--r-- | test cases/rust/5 polyglot static/stuff.rs | 6 |
4 files changed, 42 insertions, 6 deletions
diff --git a/test cases/rust/5 polyglot static/clib.c b/test cases/rust/5 polyglot static/clib.c index 366dbe5..84749de 100644 --- a/test cases/rust/5 polyglot static/clib.c +++ b/test cases/rust/5 polyglot static/clib.c @@ -1,6 +1,7 @@ #include <stdio.h> +#include <stdint.h> -void hello_from_rust(void); +int32_t hello_from_rust(const int32_t a, const int32_t b); static void hello_from_c(void) { printf("Hello from C!\n"); @@ -8,5 +9,6 @@ static void hello_from_c(void) { void hello_from_both(void) { hello_from_c(); - hello_from_rust(); + if (hello_from_rust(2, 3) == 5) + printf("Hello from Rust!\n"); } diff --git a/test cases/rust/5 polyglot static/meson.build b/test cases/rust/5 polyglot static/meson.build index 22c0cd0..5d1f023 100644 --- a/test cases/rust/5 polyglot static/meson.build +++ b/test cases/rust/5 polyglot static/meson.build @@ -17,3 +17,10 @@ e = executable('prog', 'prog.c', link_with : l, install : true) test('polyglottest', e) + +# Create a version that has overflow-checks on, then run a test to ensure that +# the overflow-checks is larger than the other version by some ammount +r2 = static_library('stuff2', 'stuff.rs', rust_crate_type : 'staticlib', rust_args : ['-C', 'overflow-checks=on']) +l2 = static_library('clib2', 'clib.c') +e2 = executable('prog2', 'prog.c', link_with : [r2, l2]) +test('overflow-checks', find_program('overflow_size_checks.py'), args : [e, e2]) diff --git a/test cases/rust/5 polyglot static/overflow_size_checks.py b/test cases/rust/5 polyglot static/overflow_size_checks.py new file mode 100755 index 0000000..9a6a64a --- /dev/null +++ b/test cases/rust/5 polyglot static/overflow_size_checks.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +# Copyright © 2023 Intel Corporation + +from __future__ import annotations +import argparse +import os +import typing as T + +if T.TYPE_CHECKING: + class Arguments(T.Protocol): + checks_off: str + checks_on: str + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument('checks_off') + parser.add_argument('checks_on') + args: Arguments = parser.parse_args() + + off = os.stat(args.checks_off).st_size + on = os.stat(args.checks_on).st_size + + assert on > off, f'Expected binary built with overflow-checks to be bigger, but it was smaller. with: "{on}"B, without: "{off}"B' + + +if __name__ == "__main__": + main() diff --git a/test cases/rust/5 polyglot static/stuff.rs b/test cases/rust/5 polyglot static/stuff.rs index 3777ae8..c312441 100644 --- a/test cases/rust/5 polyglot static/stuff.rs +++ b/test cases/rust/5 polyglot static/stuff.rs @@ -1,6 +1,4 @@ -#![crate_name = "stuff"] - #[no_mangle] -pub extern "C" fn hello_from_rust() { - println!("Hello from Rust!"); +pub extern "C" fn hello_from_rust(a: i32, b: i32) -> i32 { + a + b } |