Skip to content

Commit 509ebfe

Browse files
committed
rewrite return-non-c-like-enum-from-c to rmake
1 parent 3de0a7c commit 509ebfe

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

src/tools/run-make-support/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,26 @@ pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str)
328328
count
329329
}
330330

331+
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
332+
#[track_caller]
333+
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
334+
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
335+
let src = format!("{lib_name}.c");
336+
let lib_path = static_lib_name(lib_name);
337+
if is_msvc() {
338+
cc().arg("-c").out_exe(&obj_file).input(src).run();
339+
} else {
340+
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
341+
};
342+
let mut obj_file = PathBuf::from(format!("{lib_name}.o"));
343+
if is_msvc() {
344+
obj_file.set_extension("");
345+
obj_file.set_extension("obj");
346+
}
347+
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
348+
path(lib_path)
349+
}
350+
331351
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
332352
/// available on the platform!
333353
#[track_caller]

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ run-make/no-alloc-shim/Makefile
8383
run-make/no-builtins-attribute/Makefile
8484
run-make/no-duplicate-libs/Makefile
8585
run-make/panic-abort-eh_frame/Makefile
86-
run-make/pass-non-c-like-enum-to-c/Makefile
8786
run-make/pdb-buildinfo-cl-cmd/Makefile
8887
run-make/pgo-gen-lto/Makefile
8988
run-make/pgo-gen-no-imp-symbols/Makefile

tests/run-make/return-non-c-like-enum-from-c/Makefile

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// A reversed version of the `return-non-c-like-enum` test, though
2+
// this time, the C code is the library, and the Rust code compiles
3+
// into the executable. Once again, enum variants should be treated
4+
// like an union of structs, which should prevent segfaults or
5+
// unexpected results.
6+
// See https://github.com/rust-lang/rust/issues/68190
7+
8+
//@ ignore-cross-compile
9+
// Reason: the compiled binary is executed
10+
11+
use run_make_support::{build_native_static_lib, run, rustc};
12+
13+
fn main() {
14+
build_native_static_lib("test");
15+
rustc().input("nonclike.rs").arg("-ltest").run();
16+
run("nonclike");
17+
}

0 commit comments

Comments
 (0)