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

clang: skip the -nostdlibinc patch on Darwin; ld64: search standard library locations #349555

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

emilazy
Copy link
Member

@emilazy emilazy commented Oct 18, 2024

It kind of feels like we should find a better way of doing this on Linux too, but I’m picking the conservative option for now. Not tested in any way yet.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@emilazy emilazy requested review from a team October 18, 2024 15:19
@github-actions github-actions bot added the 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related label Oct 18, 2024
Copy link
Member

@alyssais alyssais left a comment

Choose a reason for hiding this comment

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

Shouldn't this be targetPlatform? When cross compiling from Darwin to Linux, we'd want the same behaviour as building natively on Linux, right?

@emilazy
Copy link
Member Author

emilazy commented Oct 18, 2024

Yyyyes, maybe. Except the reasoning for why it’s safe and won’t cause things like #151879 is based on properties of Darwin as a host platform. So I don’t know, really. Part of me hopes that when cross to Darwin is a thing we’ll have figured out a way to get rid of this patch on Linux too, but I can change it to targetPlatform if you think it’s best, since after all there is no way to hurt yourself with it currently anyway.

@emilazy
Copy link
Member Author

emilazy commented Oct 18, 2024

Oh, sorry, I misread you as talking about cross the other way around. I think it is safe for cross to Linux. This patch is only here to stop host platform stuff leaking in on non‐NixOS Linux. But it can’t really leak in on macOS because the stuff that would leak in isn’t there. And you’d have a cross sysroot for that case, anyway. But I guess the compiler would behave slightly differently (i.e., better, basically).

@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Oct 18, 2024
Comment on lines 84 to 94
'' + (
# See the comment on the `add-nostdlibinc-flag.patch` patch in
# `../default.nix` for why we skip Darwin here.
if lib.versionOlder release_version "13" && !stdenv.hostPlatform.isDarwin then ''
sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \
-e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \
lib/Driver/ToolChains/*.cpp
'' else ''
(cd tools && ln -s ../../clang-tools-extra extra)
''
) + lib.optionalString stdenv.hostPlatform.isMusl ''
Copy link
Contributor

@paparodeo paparodeo Oct 18, 2024

Choose a reason for hiding this comment

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

this is removed in #348568 i think.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, 8708697.

Copy link
Contributor

Choose a reason for hiding this comment

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

It’s replaced with a patch, but I think the logic of not using it on Darwin would remain in that case.

@ofborg ofborg bot added the 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild label Oct 18, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Oct 18, 2024
@reckenrode
Copy link
Contributor

reckenrode commented Oct 20, 2024

This is the issue and PR that added the patch. It fixed a build failure on Linux. I tried looking through the history, but this behavior has been around for quite a while. I also assume it’s purity related, but I don’t know.

#151879

#153963

@Ericson2314
Copy link
Member

Ericson2314 commented Oct 20, 2024

The name of the patch seems confusing? It implies is adding a flag, which should be harmless? But then the comment says something else.

Oh nevermind adding a flag to the actual command line, not support for a flag

@niklaskorz niklaskorz mentioned this pull request Oct 20, 2024
13 tasks
@emilazy
Copy link
Member Author

emilazy commented Oct 21, 2024

So the situation is:

  1. This reasoning for why this patch is harmful and requires annoying workarounds in downstream packages applies to targeting macOS.

  2. The reasoning for why this patch is mostly doesn’t prevent any brokenness applies to building on macOS.

  3. Theoretically, this change is backwards‐incompatible in very marginal cases where you’re running an unsandboxed build on macOS without any SDK and have Homebrew headers installed. One could construe this as a breaking change to a Release Critical Package, although I think the circumstances in which it would arise are very much not release‐critical.

Ideally, the patch should be applied based on targetPlatform. However, that would expose a hypothetical Linux‐to‐Darwin cross toolchain to regressions of the bugs Randy linked. I don’t know whether we care about that, especially as such toolchains don’t currently exist. Perhaps it could apply when both the host and target platform are Darwin for now to be conservative? I will go with whatever people think is best.

I would like to get this in for 24.11 because currently Rust bindgen stuff is broken on macOS and I don’t think it’s meaningfully backwards‐incompatible in a way that anyone will notice, but pinging @RossComputerGuy just in case.

@emilazy emilazy changed the title clang: skip the -nostdlibinc patch on Darwin clang: skip the -nostdlibinc patch on Darwin; ld64: search standard library locations Oct 23, 2024
@emilazy
Copy link
Member Author

emilazy commented Oct 23, 2024

Pushed to clean up now‐unnecessary hacks in the Darwin stdenv, and apply the same change to ld64 as @reckenrode pointed out that the same issues came up there with things like the .NET build. Will get some builds run to test that I didn’t break anything here.

I also conditionalized the patch on both the host and target platform being Darwin for maximum safety for now. Hopefully in the future we can avoid the sysroot weirdness that makes this necessary on Linux hosts entirely.

@github-actions github-actions bot removed the 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related label Oct 23, 2024
Copy link
Member

@RossComputerGuy RossComputerGuy left a comment

Choose a reason for hiding this comment

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

LGTM before the 25th.

Copy link
Contributor

@niklaskorz niklaskorz left a comment

Choose a reason for hiding this comment

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

zed-editor now builds fine on darwin without the NIX_CFLAGS_COMPILE = "-F${apple-sdk_15.sdkroot}/System/Library/Frameworks"; workaround for rust-bindgen 🥳

┏━ Dependency Graph:
┃    ┌─ ✔ blade-util-0.1.0 ⏱ 1s
┃    ├─ ✔ blade-macros-0.3.0 ⏱ 1s
┃    ├─ ✔ tree-sitter-gowork-0.0.1
┃    ├─ ✔ tree-sitter-heex-0.0.1
┃    ├─ ✔ xim-ctext-0.3.0
┃    ├─ ✔ tree-sitter-md-0.3.2
┃    ├─ ✔ xim-0.4.0
┃    ├─ ✔ xim-parser-0.2.1
┃    ├─ ✔ xkbcommon-0.7.0
┃    ├─ ✔ tree-sitter-yaml-0.6.1 ⏱ 8s
┃ ┌─ ✔ cargo-vendor-dir ⏱ 34s
┃ ├─ ✔ cargo-bundle-unstable-2023-08-18 ⏱ 2m46s
┃ ├─ ✔ cargo-about-0.6.4 ⏱ 3m47s
┃ ✔ zed-editor-0.157.5 ⏱ 41m5s
┣━━━ Builds
┗━ ∑ ⏵ 0 │ ✔ 1903 │ ⏸ 0 │ Finished at 08:30:05 after 11h24m32s

emilazy added a commit to emilazy/nixpkgs that referenced this pull request Oct 24, 2024
We have to leave the flags in the wrapper until the bootstrap tools
are updated, but drop the redundant `-isysroot` to fix issues like
<NixOS#349555>.
@emilazy
Copy link
Member Author

emilazy commented Oct 24, 2024

Zed working confirms that this PR accomplishes its primary goal 🎉 Still waiting to hear about .NET. Swift is being a pain and we might have to back out those changes for now. Testing dropping the redundant -isysroot to fix #350853.

@alyssais
Copy link
Member

Ack.

@github-actions github-actions bot added the 6.topic: stdenv Standard environment label Oct 24, 2024
@nix-owners nix-owners bot requested a review from toonn October 24, 2024 15:55
@emilazy emilazy force-pushed the push-smtsootnqmlv branch 2 times, most recently from 6013ee9 to 670a9d2 Compare October 24, 2024 17:04
This is basically harmless for the same reason as it is for Clang, and
lets us avoid doing wrapper hacks to fix things like the .NET build.

This reverts commit 4340a5a.
@emilazy emilazy changed the title clang: skip the -nostdlibinc patch on Darwin; {ld64,swift}: search standard library locations clang: skip the -nostdlibinc patch on Darwin; ld64: search standard library locations Oct 24, 2024
@emilazy
Copy link
Member Author

emilazy commented Oct 24, 2024

Dropped the Swift changes; it’s too haunted to deal with right now and it works okay without the commit. Moved the flags for backwards‐compatibility with the current bootstrap tools into the stdenv. This should be ready to go pending confirmation that it does in fact build .NET successfully.

@ofborg ofborg bot requested a review from RossComputerGuy October 24, 2024 22:23
@emilazy
Copy link
Member Author

emilazy commented Oct 25, 2024

Summary of the state of things: it bootstraps fine and fixes the regression, can build Swift, Zed, etc., but the .NET build fails due to Swift‐related ld64 wrapper flag issues that need to be diagnosed; it’s possible that part of the flags wrapper just needs to be restored, at least for now, though it could also theoretically be worked around in the .NET rebuild. I will investigate tomorrow; I hope it is okay for this to miss the deadline by a day since the circumstances in which this is at all a breaking change are very marginal and it will be many days before the staging cycle this lands in even starts anyway.

@emilazy emilazy marked this pull request as draft October 25, 2024 00:02
@emilazy emilazy marked this pull request as ready for review October 25, 2024 00:37
@emilazy
Copy link
Member Author

emilazy commented Oct 25, 2024

It turns out that .NET’s build system just has -L/usr/lib/swift references that our awful CMake hook was obliterating and we were inadvertently working around that, and everything about our toolchain is actually working as expected with this PR. We may want to consider automatically adding usr/lib/swift to match the closed‐source ld-prime in the future, but that’s out of scope for this. It’s less than an hour late (in UTC) so hopefully this is okay to merge.

@reckenrode reckenrode mentioned this pull request Oct 25, 2024
12 tasks
@reckenrode
Copy link
Contributor

The stdenv changes LGTM.

@emilazy emilazy merged commit 4b8e58e into NixOS:staging Oct 25, 2024
32 of 35 checks passed
@emilazy emilazy deleted the push-smtsootnqmlv branch October 25, 2024 00:56
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/the-darwin-sdks-have-been-updated/55295/26

@Liamolucko Liamolucko mentioned this pull request Dec 9, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 6.topic: stdenv Standard environment 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ 10.rebuild-linux-stdenv This PR causes stdenv to rebuild
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants