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

Clarify build.rs C compiler and linker configuration. #1697

Merged
merged 4 commits into from
Oct 6, 2023

Conversation

briansmith
Copy link
Owner

See each individual commit message for details.

@briansmith briansmith self-assigned this Oct 5, 2023
// Compile all the (dirty) source files into object files.
let objs = additional_srcs
.iter()
.chain(srcs.iter())
.map(|f| compile(f, target, out_dir, out_dir))
.map(|f| compile(&c, f, target, out_dir, out_dir))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now all the calls to compile() share a single build configuration that is constructed once per library, instead of once per source file.

.collect::<Vec<_>>();

// Rebuild the library if necessary.
let lib_path = PathBuf::from(out_dir).join(format!("lib{}.a", lib_name));

let mut c = cc::Build::new();

for f in LD_FLAGS {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LD_FLAGS was empty so this wasn't doing anything.

build.rs Show resolved Hide resolved
build.rs Outdated Show resolved Hide resolved
match ext {
"c" | "S" => (),
e => panic!("Unsupported file extension: {:?}", e),
};
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the top of the new cc().

Clarify which parts of the build script modify the compiler
configuration (`configure_cc`) and which don't (`cc`). Ensure that the
configuration is only done once per library, instead of once per source
file, as each `cc` invocation can reuse the configuration work done by
a single `configure_cc` call.
@briansmith briansmith force-pushed the b/simplify-build.rs-1 branch from ace2a13 to 43eb390 Compare October 5, 2023 19:55
@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Merging #1697 (ae3dcc2) into main (9d2abfc) will increase coverage by 0.01%.
The diff coverage is n/a.

❗ Current head ae3dcc2 differs from pull request most recent head 34f6ec8. Consider uploading reports for the commit 34f6ec8 to get more accurate results

@@            Coverage Diff             @@
##             main    #1697      +/-   ##
==========================================
+ Coverage   95.97%   95.98%   +0.01%     
==========================================
  Files         134      134              
  Lines       19980    19980              
  Branches      199      199              
==========================================
+ Hits        19175    19177       +2     
  Misses        767      767              
+ Partials       38       36       -2     

see 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

cc-rs's documentation says that it already handles this automatically,
which is why we'd already removed it for other targets.
First, we were passing `-Wl,--gc-sections` to the compiler regardless
of whether it is MSVC, which didn't make any sense on its own.

But, even more generally, it doesn't make sense for us to try to tell
the linker what to do when we aren't actually linking. (We're building
static libraries of the C and assembly code.)
@briansmith briansmith force-pushed the b/simplify-build.rs-1 branch 2 times, most recently from ae3dcc2 to 34f6ec8 Compare October 6, 2023 02:19
@briansmith briansmith merged commit 3a650b3 into main Oct 6, 2023
157 of 158 checks passed
@briansmith briansmith deleted the b/simplify-build.rs-1 branch October 6, 2023 03:10
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

Successfully merging this pull request may close these issues.

1 participant