Closed jessicah closed 2 years ago
Could you add a testcase? Also, please do not increment the version number in this PR.
I'm having trouble running the tests; is cd testcrate && cargo test
supposed to work? I get multiple definition
errors on both Linux and Haiku.
/usr/bin/ld: .../libtestcrate.rlib(t1gen.o):/.../testcrate/src/t1.h:65: multiple definition of `T1_static_mut_u8'; .../libtestcrate.rlib(t1.o):/.../testcrate/src/t1.h:65: first defined here
/usr/bin/ld: .../libtestcrate.rlib(t1gen.o):/.../testcrate/src/t1.h:66: multiple definition of `T1_static_mut_fn_ptr'; .../libtestcrate.rlib(t1.o):/.../testcrate/src/t1.h:66: first defined here
/usr/bin/ld: .../libtestcrate.rlib(t1gen.o):/.../testcrate/src/t1.h:72: multiple definition of `T1_static_right2'; .../libtestcrate.rlib(t1.o):/.../testcrate/src/t1.h:72: first defined here
/usr/bin/ld: .../libtestcrate.rlib(t1gen.o):/.../testcrate/src/t1.h:77: multiple definition of `T1_fn_ptr_s'; .../libtestcrate.rlib(t1.o):/.../testcrate/src/t1.h:77: first defined here
/usr/bin/ld: .../libtestcrate.rlib(t1gen.o):/.../testcrate/src/t1.h:82: multiple definition of `T1_fn_ptr_s2'; .../libtestcrate.rlib(t1.o):/.../testcrate/src/t1.h:82: first defined here
/usr/bin/ld: .../libtestcrate.rlib(t1gen.o):/.../testcrate/src/t1.h:101: multiple definition of `T1_opt_fn2'; .../libtestcrate.rlib(t1.o):/.../testcrate/src/t1.h:101: first defined here
/usr/bin/ld: .../libtestcrate.rlib(t1gen.o):/.../testcrate/src/t1.h:102: multiple definition of `T1_opt_fn3'; .../libtestcrate.rlib(t1.o):/.../testcrate/src/t1.h:102: first defined here
/usr/bin/ld: .../libtestcrate.rlib(t1gen.o):/.../testcrate/src/t1.h:157: multiple definition of `T1_fn_ptr_vol'; .../libtestcrate.rlib(t1.o):/.../testcrate/src/t1.h:157: first defined here
collect2: error: ld returned 1 exit status
Running cargo test
in the root appears to only run the no_run
test code from src/lib.rs
? Sorry, I'm not too familiar with the whole cargo test
stuff.
Well, I can reproduce that failure too, what's weird is it doesn't reproduce on CI (GCC version difference?). I don't have time to investigate right now, could you use CI for testing?
Oh, I see, the tests in testcrate
have been explicitly disabled. I ran the CI test on top of current tip with the above patch, and no test failures, so not sure what my next step is for adding a test, given that testcrate
tests don't work properly.
And I have already used this patch on Haiku, as it was needed for testing my changes to the libc
crate, similar to what your CI already does.
As this change is for the generated __test_fn
declarations, I can't see why you'd ever want non-C linkage. Even when using c++
, surely Rust is expecting C linkage? It also matches other generated test wrappers that using C linkage, e.g. __test_offset
, __test_fsize
, __test_size
, __test_align
, __test_signed
, __test_const
, and __test_roundtrip
all use C linkage.
Fair enough
When using
Lang::CXX
, these ended up with C++ linkage, causing linking to fail.