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

CMake: Set CMAKE_OSX_ only on Darwin? #94952

Closed
primeos opened this issue Aug 8, 2020 · 9 comments
Closed

CMake: Set CMAKE_OSX_ only on Darwin? #94952

primeos opened this issue Aug 8, 2020 · 9 comments
Labels
0.kind: enhancement 6.topic: darwin Running or building packages on Darwin

Comments

@primeos
Copy link
Member

primeos commented Aug 8, 2020

In 68513e4 (part of #77632) CMAKE_OSX_ARCHITECTURES=x86_64 was moved from pkgs/stdenv/darwin/default.nix to pkgs/development/tools/build-managers/cmake/setup-hook.sh. As a result -DCMAKE_OSX_ARCHITECTURES=x86_64 is since then set on Linux as well.
Until now this wasn't a problem as https://cmake.org/cmake/help/v3.18/variable/CMAKE_OSX_ARCHITECTURES.html states that:

This variable is ignored on platforms other than Apple.

Unfortunately that behaviour changed in CMake 3.18:

To avoid such regressions in the future it might be a good idea to set the following two CMake flags (source) only on Darwin:

    # on macOS i686 was only relevant for 10.5 or earlier.
    cmakeFlags="-DCMAKE_OSX_ARCHITECTURES=x86_64 $cmakeFlags"

    # we never want to use the global macOS SDK
    cmakeFlags="-DCMAKE_OSX_SYSROOT= $cmakeFlags"

cc CMake maintainers: @ttuegel @LnL7
cc @orivej (found this regression)

@ttuegel
Copy link
Member

ttuegel commented Aug 9, 2020

I don't think setting it as an environment variable will have any effect, so we will need to put a guard around it in the setup hook.

doronbehar added a commit to doronbehar/nixpkgs that referenced this issue Aug 10, 2020
@matthewbauer
Copy link
Member

matthewbauer commented Aug 13, 2020

I think just adding if [ "$(uname)" = Darwin ] on the CMake setup-hook is probably the easiest fix.

@doronbehar
Copy link
Contributor

Why not use a Nix conditional? It should spare at least the Darwin rebuilds if done right.

@veprbl veprbl added the 6.topic: darwin Running or building packages on Darwin label Aug 19, 2020
@matthewbauer
Copy link
Member

Why not use a Nix conditional? It should spare at least the Darwin rebuilds if done right.

That will probably work, but splitting the setup hook could be a little tricky. We'd need two setup hooks - one for all systems, and one for darwin (and maybe even one for linux for consistency). It would definitely be better for issues like these in the future, but I'm always a little hesitant to rework some of the Bash logic given its brittleness.

@primeos
Copy link
Member Author

primeos commented Aug 19, 2020

I think just adding if [ "$(uname)" = Darwin ] on the CMake setup-hook is probably the easiest fix.

I kinda like that idea as it's simple and minimal. Though that might cause problems for cross-builds (if that even works between e.g. Darwin and Linux)? Would be nice if there would be an environment variable available in the Nix build for this (both with and without sandboxing).

That will probably work, but splitting the setup hook could be a little tricky.

Yeah, I guess merging the common parts is the most tricky part. One option could be to add scripts for Linux and Darwin that set and export an environment variable and then source setup-hook.sh? Or I guess we could use Nix conditionals if we change setup-hook.sh; to a Nix expression like writeText (but that would likely be less optimal as it won't be recognized as a shell script if we cannot somehow read the content of setup-hook.sh and interpret it as text with Nix expressions).

@stale
Copy link

stale bot commented Feb 15, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Feb 15, 2021
@kvtb
Copy link
Contributor

kvtb commented Aug 24, 2021

Another problem: since libjpeg-turbo/libjpeg-turbo@399aa37 libjpeg-turbo is broken on i686-linux.

cmakeFlags = [ "-DCMAKE_OSX_ARCHITECTURES=" does fix the build, but it would be much better if OSX featues won't leak into Linux at all.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 24, 2021
@kvtb
Copy link
Contributor

kvtb commented Aug 24, 2021

I hope it is fixed in #114817

@primeos
Copy link
Member Author

primeos commented Aug 25, 2021

Nice! d16a875 (#114817) fixes/avoids the issues came from CMAKE_OSX_ARCHITECTURES so I guess we can close this now.

CMAKE_OSX_SYSROOT is still set on Linux but at least that didn't seem to cause any issues so far. If someone has time and motivation it might be nice to drop it on Linux as well (like in d16a875).

@primeos primeos closed this as completed Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: enhancement 6.topic: darwin Running or building packages on Darwin
Projects
None yet
Development

No branches or pull requests

6 participants