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

Don't pass -stdlib=libc++ when building C files on macOS #116017

Merged
merged 1 commit into from
Nov 5, 2023

Conversation

Zalathar
Copy link
Contributor

When using Command Line Tools for Xcode version 15.0, clang will warn about argument unused during compilation: '-stdlib=libc++' if this flag is present when compiling C files only (i.e. no C++ files).

To avoid this warning, we can add the flag only to CXXFLAGS and not to CFLAGS.


Zulip thread

@rustbot
Copy link
Collaborator

rustbot commented Sep 21, 2023

r? @albertlarsan68

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Sep 21, 2023
@Zalathar
Copy link
Contributor Author

It's possible that this flag is no longer needed at all (since some sources claim that libc++ should be the default anyway), but since my main goal here is to get rid of the warning while I'm building, I didn't do the extra work of fully tracking that down.

@Zalathar
Copy link
Contributor Author

The warning started appearing after I accepted a system update of Command Line Tools for Xcode from version 14.3 to 15.0.

Presumably the older compiler was accepting the argument and silently doing nothing with it, whereas the newer compiler now correctly identifies that the flag has no effect on C code. But since I no longer have the older compiler on my system, I can't test that hypothesis directly.

@albertlarsan68
Copy link
Member

@rustbot ping macos
Does this fix the problem / does anything break ?

@rustbot rustbot added the O-macos Operating system: macOS label Sep 24, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 24, 2023

Hey MacOS Group! This issue or PR could use some MacOS-specific guidance. Could one
of you weigh in? Thanks <3

cc @hkratz @inflation @nvzqz @shepmaster @thomcc

@thomcc
Copy link
Member

thomcc commented Sep 24, 2023

What's a configuration where I can reproduce the issue?

@Zalathar
Copy link
Contributor Author

This is my config.toml:

profile = "codegen"
changelog-seen = 2

[build]
profiler = true
low-priority = true

[rust]
llvm-tools = true
deny-warnings = false

I'm on macOS Ventura 13.5.2, using Apple's Command Line Tools for Xcode version 15.0:

$ clang --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

If I just do x build library as normal, I see plenty of warnings in my terminal about -stdlib=libc++ being unused.

When I started investigating the warnings, I switched to x build library/profiler_builtins --stage=0, as it's very fast and has very little output other than the warnings.

@Zalathar
Copy link
Contributor Author

Zalathar commented Sep 25, 2023

This is what I see before applying this PR:

$ x build library/profiler_builtins --stage=0
Building bootstrap
    Finished dev [unoptimized] target(s) in 0.03s
Building stage0 library artifacts {profiler_builtins} (aarch64-apple-darwin)
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
warning: clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
    Finished release [optimized] target(s) in 0.07s
Build completed successfully in 0:00:00

Each warning corresponds to one of the .c files listed in library/profiler_builtins/build.rs.

(The number of warnings doesn't quite match the number of files because one of the listed files is a .cpp file that doesn't warn, and one of the .c files doesn't actually exist. But if I comment out one of the other C files in the list, the number of warnings decreases by one.)

@Zalathar
Copy link
Contributor Author

After applying this PR:

$ x build library/profiler_builtins --stage=0
Building bootstrap
    Finished dev [unoptimized] target(s) in 0.03s
Building stage0 library artifacts {profiler_builtins} (aarch64-apple-darwin)
    Finished release [optimized] target(s) in 0.07s
Build completed successfully in 0:00:00

@inflation
Copy link

Is there any difference if you have gcc and libstdc++ in search path?

@Zalathar
Copy link
Contributor Author

I don't have GCC installed on my system, so I don't know what the difference would be.

@Zalathar
Copy link
Contributor Author

This is what happens when I ask clang to compile simple C and C++ files, with and without the flag:

$ clang --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ echo 'int main(int argc, char** argv) { return 0; }' > foo.cpp

$ cp foo.cpp bar.c

$ clang foo.cpp

$ clang -stdlib=libc++ foo.cpp

$ clang bar.c

$ clang -stdlib=libc++ bar.c
clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]

@bors
Copy link
Contributor

bors commented Oct 17, 2023

☔ The latest upstream changes (presumably #116196) made this pull request unmergeable. Please resolve the merge conflicts.

When using *Command Line Tools for Xcode* version 15.0, clang will warn about
`argument unused during compilation: '-stdlib=libc++'` if this flag is present
when compiling C files only (i.e. no C++ files).

To avoid this warning, we can add the flag only to CXXFLAGS and not to CFLAGS.
@albertlarsan68
Copy link
Member

Thanks for the PR!
@bors r+

@bors
Copy link
Contributor

bors commented Nov 5, 2023

📌 Commit 9eb70d6 has been approved by albertlarsan68

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 5, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 5, 2023
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#116017 (Don't pass `-stdlib=libc++` when building C files on macOS)
 - rust-lang#117524 (bootstrap/setup: create hooks directory if non-existing)
 - rust-lang#117588 (Remove unused LoadResult::DecodeIncrCache variant)
 - rust-lang#117596 (Add diagnostic items for a few of core's builtin macros)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit db66598 into rust-lang:master Nov 5, 2023
11 checks passed
@rustbot rustbot added this to the 1.75.0 milestone Nov 5, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 5, 2023
Rollup merge of rust-lang#116017 - Zalathar:darwin-stdlib, r=albertlarsan68

Don't pass `-stdlib=libc++` when building C files on macOS

When using *Command Line Tools for Xcode* version 15.0, clang will warn about `argument unused during compilation: '-stdlib=libc++'` if this flag is present when compiling C files only (i.e. no C++ files).

To avoid this warning, we can add the flag only to CXXFLAGS and not to CFLAGS.

---

[Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/clang.20warning.3A.20argument.20unused.20during.20compilation.20.28libc.2B.2B.29)
@bors
Copy link
Contributor

bors commented Nov 5, 2023

⌛ Testing commit 9eb70d6 with merge 04817ff...

@Zalathar Zalathar deleted the darwin-stdlib branch November 5, 2023 20:26
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Nov 6, 2023
84: Automated pull from upstream `master` r=Dajamante a=github-actions[bot]


This PR pulls the following changes from the upstream repository:

* rust-lang/rust#117585
* rust-lang/rust#117576
* rust-lang/rust#96979
* rust-lang/rust#117191
* rust-lang/rust#117179
* rust-lang/rust#117574
* rust-lang/rust#117537
* rust-lang/rust#117608
  * rust-lang/rust#117596
  * rust-lang/rust#117588
  * rust-lang/rust#117524
  * rust-lang/rust#116017
* rust-lang/rust#117504
* rust-lang/rust#117469
* rust-lang/rust#116218
* rust-lang/rust#117589
* rust-lang/rust#117581
* rust-lang/rust#117503
* rust-lang/rust#117590
  * rust-lang/rust#117583
  * rust-lang/rust#117570
  * rust-lang/rust#117562
  * rust-lang/rust#117534
  * rust-lang/rust#116894
  * rust-lang/rust#110340
* rust-lang/rust#113343
* rust-lang/rust#117579
* rust-lang/rust#117094
* rust-lang/rust#117566
* rust-lang/rust#117564
  * rust-lang/rust#117554
  * rust-lang/rust#117550
  * rust-lang/rust#117343
* rust-lang/rust#115274
* rust-lang/rust#117540
* rust-lang/rust#116412
* rust-lang/rust#115333
* rust-lang/rust#117507
* rust-lang/rust#117538
  * rust-lang/rust#117533
  * rust-lang/rust#117523
  * rust-lang/rust#117520
  * rust-lang/rust#117505
  * rust-lang/rust#117434
* rust-lang/rust#117535
* rust-lang/rust#117510
* rust-lang/rust#116439
* rust-lang/rust#117508



Co-authored-by: Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
Co-authored-by: SabrinaJewson <sejewson@gmail.com>
Co-authored-by: J-ZhengLi <lizheng135@huawei.com>
Co-authored-by: koka <koka.code@gmail.com>
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Co-authored-by: Joshua Liebow-Feeser <joshlf@users.noreply.github.com>
Co-authored-by: lengyijun <sjtu5140809011@gmail.com>
Co-authored-by: Zalathar <Zalathar@users.noreply.github.com>
Co-authored-by: Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Co-authored-by: Philipp Krones <hello@philkrones.com>
Co-authored-by: y21 <30553356+y21@users.noreply.github.com>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: bohan <bohan-zhang@foxmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-macos Operating system: macOS S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants