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

macOS: spkg-install scripts that force use of clang conflict with '-march=native' #30725

Closed
mkoeppe opened this issue Oct 5, 2020 · 60 comments
Closed

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented Oct 5, 2020

Several packages force the use of clang because they cannot be built with a real gcc due to the use of Apple language extensions in system header files.

For these packages, the use of -march=native introduced in #27122 causes build errors because clang does not understand these flags (even though /usr/bin/gcc does).

Tickets where code setting the compiler was explicitly introduced: #22999 (cmake), ....

$ git grep MACOSX_VERSION
build/pkgs/curl/spkg-install.in:        echo "OS X 10.$[$MACOSX_VERSION-4] Building with clang and --with-darwinssl."
build/pkgs/psutil/spkg-install.in:    echo "OS X 10.$[$MACOSX_VERSION-4] Building with clang."
build/pkgs/python3/spkg-build.in:        echo "OS X 10.$[$MACOSX_VERSION-4] Building with clang."
build/pkgs/r/spkg-install.in:        echo "OS X 10.$[$MACOSX_VERSION-4] Building with clang."

To test:

tox -e local-homebrew-macos-minimal
tox -e local-homebrew-macos-minimal -- cmake curl gmp
tox -e local-homebrew-macos-minimal -- ptest

To test with a real gcc (using a gcc-10 installed from homebrew):

tox -e local-direct-gcc_10 -- cmake curl gmp python3 psutil r

CC: @jhpalmieri @dimpase @kliem @zlscherr @kiwifb @seblabbe

Component: porting

Author: Matthias Koeppe, Jonathan Kliem

Branch/Commit: f56e65e

Reviewer: Jonathan Kliem, Matthias Koeppe

Issue created by migration from https://trac.sagemath.org/ticket/30725

@mkoeppe mkoeppe added this to the sage-9.3 milestone Oct 5, 2020
@mkoeppe mkoeppe changed the title macOS: spkg-install: Remove outdated "Building with clang" branches macOS: spkg-install: Remove outdated "Building with clang" code - which conflicts with '-march=native' Jan 16, 2021
@mkoeppe

This comment has been minimized.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 16, 2021

Dependencies: #31186

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2021

Changed dependencies from #31186 to none

@mkoeppe

This comment has been minimized.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2021

@kiwifb
Copy link
Member

kiwifb commented Jan 18, 2021

comment:8

Those bits should have gone when I "normalised" clang for building sage on OS X. We were probably planing to remove them at a later stage and forgot.

Well, the opportunity is clearly now.


New commits:

1cb38cdtox.ini: Add configuration factor gcc_10
f190f51build/pkgs/cmake/spkg-install.in: Do not explicitly use clang on macos
0c89bc0build/pkgs/{gmp,mpir}/spkg-install.in: Do not override compiler set explicitly to clang
178a490build/pkgs/pari/spkg-install.in: Do not recompute MACOSX_VERSION
13ef685build/pkgs/python3/spkg-build.in: Do not explicitly use clang on macos
2a5e7dbbuild/pkgs/r/spkg-install.in: Do not explicitly use clang on macos
c187d65build/pkgs/psutil/spkg-install.in: Do not explicitly use clang on macos
3fd3388build/pkgs/curl/spkg-install.in: Do not explicitly use clang on macos

@kiwifb
Copy link
Member

kiwifb commented Jan 18, 2021

Commit: 3fd3388

@mkoeppe

This comment has been minimized.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2021

comment:10

Also several of these packages have been updated since and are able to build with an actual gcc on macOS. We have tickets for some packages where this is still broken: #29613 (givaro)

@mkoeppe

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 18, 2021

Changed commit from 3fd3388 to 2a39819

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 18, 2021

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

5bc544cbuild/pkgs/cmake/spkg-install.in: Do not explicitly use clang on macos
da4ea53build/pkgs/{gmp,mpir}/spkg-install.in: Do not override compiler set explicitly to clang
05b06b2build/pkgs/pari/spkg-install.in: Do not recompute MACOSX_VERSION
e796b8abuild/pkgs/python3/spkg-build.in: Do not explicitly use clang on macos
5895d23build/pkgs/r/spkg-install.in: Do not explicitly use clang on macos
350bc01build/pkgs/psutil/spkg-install.in: Do not explicitly use clang on macos
2a39819build/pkgs/curl/spkg-install.in: Do not explicitly use clang on macos

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2021

Author: Matthias Koeppe

@kliem
Copy link
Contributor

kliem commented Jan 18, 2021

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2021

comment:15

I have tested the configuration in the ticket description successfully.

But testing with the gcc-10 from homebrew, I am still running into issues with macOS header files that are not compatible with gcc.

  [cmake-3.18.2] installing. Log file: /Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/logs/pkgs/cmake-3.18.2.log
  [cmake-3.18.2] error installing, exit status 1. End of log file:
  [cmake-3.18.2]   /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/ImageIO.framework/Headers/CGImageAnimation.h:42:15: error: expected unqualified-id before '^' token
  [cmake-3.18.2]      42 | typedef void (^CGImageSourceAnimationBlock)(size_t index, CGImageRef image, bool* stop);
  [cmake-3.18.2]         |               ^

@kliem
Copy link
Contributor

kliem commented Jan 18, 2021

comment:16

Btw, to prevent breackage because of -march=native, one can also export CFLAGS=CFLAGS_NON_NATIVE etc. right after setting the compiler to clang.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2021

comment:17

Yes, if simple fixes such as package upgrades don't fix it, that's what we should do.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2021

comment:18

Upgrade of cmake to 3.19.3 (#31258) does not fix this

@dimpase
Copy link
Member

dimpase commented Jan 18, 2021

comment:19

I don't understand - I presume one still cannot build all of Sage on macOS using "real" gcc.

Why is this a blocker?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2021

comment:20

Replying to @dimpase:

I don't understand - I presume one still cannot build all of Sage on macOS using "real" gcc.

Yes, this is what the experiment with cmake has just revealed.

Why is this a blocker?

When Apple's compiler is invoked as clang instead of gcc, it does not understand the same flags. So #27122 leads to build errors.

@mkoeppe

This comment has been minimized.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 19, 2021

@kliem
Copy link
Contributor

kliem commented Jan 20, 2021

Changed commit from 9b0eb15 to f56e65e

@kliem
Copy link
Contributor

kliem commented Jan 20, 2021

comment:35

R does not use -march=native anyway.
python/spkg-build.in is set up a bit different. $CFLAGS contains other stuff and $EXTRA_CFLAGS is contains the old $CFLAGS, so we need to set $EXTRA_CFLAGS.

Anyway, I think the main problem is that we run testcfags.sh before setting the compiler.
We might as well run this for $CFLAGS as well after possibly changing the compiler.


New commits:

02c2684R is already compiled without -march=native
24b4fccset EXTRACFLAGS instead of CFLAGS
44be967make code a bit more stable against future changes
f56e65efix CFLAGS for python3/spkg-build.in by running testcflags.sh after determination of the compiler

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 20, 2021

comment:37

Replying to @kliem:

R does not use -march=native anyway.

... is it ignoring CFLAGS?

@kliem
Copy link
Contributor

kliem commented Jan 20, 2021

comment:38

No, it already uses CFLAGS_NON_NATIVE.

 10 # #29170: Compilation errors caused by a silently failing configure check
 11 # "for type of 'hidden' Fortran character lengths"
 12 # on ubuntu-bionic-minimal, ubuntu-eoan/focal-minimal, debian-buster/bullseye/sid-minimal,
 13 # linuxmint-19.3-minimal, archlinux-latest-minimal
 14 CFLAGS="$CFLAGS_NON_NATIVE -fPIC"
 15 FCFLAGS="$FCFLAGS_NON_NATIVE -fPIC"

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 20, 2021

comment:39

Ah, OK, thanks

@kliem
Copy link
Contributor

kliem commented Jan 20, 2021

comment:40

R was one of the things that crashed or didn't build with -march=native (don't remember), so I disalbed it in #27122.

@kliem
Copy link
Contributor

kliem commented Jan 21, 2021

comment:41

My tests finished. Not very sucessfull though. Looks like zlib failed for many mac runs.

Also ubuntu-bionic-minimal and debian-buster-minimal failed because somehow ssl wasn't available and the pytest failed (or the server did not reply).

Anyway. There are several different ways to fix python3/spkg-build.in of course.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 21, 2021

comment:42

Replying to @kliem:

My tests finished. Not very sucessfull though. Looks like zlib failed for many mac runs.

Also ubuntu-bionic-minimal and debian-buster-minimal failed because somehow ssl wasn't available and the pytest failed (or the server did not reply).

One needs to merge a few tickets that fix up the GH Actions runs.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 21, 2021

comment:43

Replying to @kliem:

There are several different ways to fix python3/spkg-build.in of course.

Are you satisfied with the version that you pushed?

@kliem
Copy link
Contributor

kliem commented Jan 22, 2021

comment:45

Replying to @mkoeppe:

Replying to @kliem:

There are several different ways to fix python3/spkg-build.in of course.

Are you satisfied with the version that you pushed?

Yes.

@kliem
Copy link
Contributor

kliem commented Jan 22, 2021

comment:46

And I'm also happy with your changes.

I'm just waiting on an okay, that this fixes things.

@zlscherr
Copy link

comment:47

Is this supposed to fix issues around using /usr/bin/python3 on Big Sur? With this ticket if I configure with-python=/usr/bin/python3 and then do make Cython I still get

gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -O2 -g -march=native -I/Users/zscherr/sage/develop/local/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c /private/var/folders/5f/z870t4kd5dlctkcrs984nh8r0000gn/T/pip-req-build-rpwm0h2y/Cython/Plex/Scanners.c -o build/temp.macosx-10.14.6-x86_64-3.8/private/var/folders/5f/z870t4kd5dlctkcrs984nh8r0000gn/T/pip-req-build-rpwm0h2y/Cython/Plex/Scanners.o
  clang: error: the clang compiler does not support '-march=native'
  error: command 'gcc' failed with exit status 1

@kliem
Copy link
Contributor

kliem commented Jan 22, 2021

comment:48

Does it go away, if you additionally pull in #31228?

This one just disables -march=native regardless, if the compiler of system python does not understand it. What might be more clever, is to just disable -march=native in the definition of sdh_pip_install.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 22, 2021

comment:49

Replying to @zlscherr:

Is this supposed to fix issues around using /usr/bin/python3 on Big Sur?

No, it's only a first step

@zlscherr
Copy link

comment:50

Replying to @kliem:

Does it go away, if you additionally pull in #31228?

This one just disables -march=native regardless, if the compiler of system python does not understand it. What might be more clever, is to just disable -march=native in the definition of sdh_pip_install.

Thanks! Yes, with this ticket and #31228 I can get python packages (at least cython) to build again using system python. I'll continue to check to make sure everything builds.

@kliem
Copy link
Contributor

kliem commented Jan 23, 2021

comment:51

I think this is good to go.

@kliem
Copy link
Contributor

kliem commented Jan 23, 2021

Changed reviewer from https://github.com/mkoeppe/sage/actions/runs/502363182, Jonathan Kliem to Jonathan Kliem

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 23, 2021

Changed author from Matthias Koeppe to Matthias Koeppe, Jonathan Kliem

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 23, 2021

Changed reviewer from Jonathan Kliem to Jonathan Kliem, Matthias Koeppe

@vbraun
Copy link
Member

vbraun commented Jan 31, 2021

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

No branches or pull requests

6 participants