Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc 1.61 breaks build script that works with 1.60 #702

Open
osa1 opened this issue Jul 22, 2022 · 2 comments
Open

rustc 1.61 breaks build script that works with 1.60 #702

osa1 opened this issue Jul 22, 2022 · 2 comments

Comments

@osa1
Copy link

osa1 commented Jul 22, 2022

I'm not sure if this is a bug in rustc, or a print line that needs to be updated in cc. If you think this is a rustc bug please let me know and I'll report this in to rustc issue tracker. The problem exists in nightly as well.

I have this simple build script: https://github.com/osa1/sg/blob/master/build.rs it runs cc 6 times in total. The generated files should be statically linked with the executable.

In each iteration the build script runs cc twice. The second file being compiled uses symbols defined in the first.

cargo build works fine with rustc 1.60. With 1.61 it fails with "undefined reference to xyz" build errors where the symbols in error messages are symbols defined in the first file and used in the second file.

When both of the files being compiled are C files, I can combine the two cc commands in the loop body with one, passing both files as inputs. If I do that the build script works fine with rustc 1.61.

However sometimes one of the files is a C++ file, and in that case I can't combine these two cc commands into one, so I can't fix this for rustc 1.61 and newer by compiling both files in one invocation of cc.

Should cc be updated for some change in rustc 1.61? I checked the changelog for 1.61. The only entry that looks somewhat relevant is rust-lang/rust#93901. However from that thread I don't see why it would break a build script that works fine with rustc 1.61..

@osa1
Copy link
Author

osa1 commented Jul 22, 2022

This is so strange.. If I swap the cc calls it works. So instead of building the dependency and then the dependant (which works in rustc older than 1.61), I build the dependant first and then the dependency.

osa1 added a commit to osa1/sg that referenced this issue Jul 22, 2022
Starting with rustc 1.61 the build script causes linker errors.

Swapping order of `cc` calls somehow "fixes" the issue. It probably
works around some bug in rustc or cargo.

See also rust-lang/cc-rs#702
@Wilfred
Copy link

Wilfred commented Aug 28, 2022

Note that rust 1.61 uses whole-archive linking in fewer cases, so linking has changed: https://github.com/rust-lang/rust/blob/1.61.0/RELEASES.md#compatibility-notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants