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
[crypto] Fix relic build script for ARM #823
Conversation
e35eb23
to
1566b16
Compare
Codecov Report
@@ Coverage Diff @@
## master #823 +/- ##
==========================================
+ Coverage 56.44% 56.71% +0.27%
==========================================
Files 427 429 +2
Lines 25088 25473 +385
==========================================
+ Hits 14160 14447 +287
- Misses 9009 9060 +51
- Partials 1919 1966 +47
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this and updating the script 👌
I left a question below.
crypto/relic_build.sh
Outdated
@@ -17,12 +17,21 @@ pushd "$DIR/relic/build" | |||
# | |||
GENERAL=(-DTIMER=CYCLE -DCHECK=OFF -DVERBS=OFF) | |||
LIBS=(-DSHLIB=OFF -DSTLIB=ON) | |||
COMP=(-DCOMP="-O3 -funroll-loops -fomit-frame-pointer -march=native -mtune=native") | |||
|
|||
# "-march=native" is not supported on ARM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did compilation on ARM fail with gcc or clang ?
It seems that gcc supports the flag (a node operator is also using gcc on ARM), but I couldn't find the same information for clang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, the flag is indeed recently supported on gcc. The OP in #809 almost certainly had issues with clang (because M1).
I've added 53ea1bc, which I hope addresses the issue more comprehensively, if at the cost of some complexity.
868f1b0
to
53ea1bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking the initiative to work on this script 🏄
I left a few comment/questions below.
crypto/relic_build.sh
Outdated
# de-mangle the CMakeLists file, done with a temp file | ||
# to be portable between GNU / BSD sed | ||
CMAKE_TEMP=$(mktemp) | ||
sed -e '/message ( STATUS "CC=$ENV{CC}" )/d' ../CMakeLists.txt > $CMAKE_TEMP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think sed -i
allows making changes in place to avoid using CMAKE_TEMP
sed -e '/message ( STATUS "CC=$ENV{CC}" )/d' ../CMakeLists.txt > $CMAKE_TEMP | |
sed -i -e '/message ( STATUS "CC=$ENV{CC}" )/d' ../CMakeLists.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I would avoid using sed
as it requires a different command on GNU and macos.
Maybe we could just avoid deleting the extra line? or use grep and only write the extra line if it doesn't exist already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the comment above the line you comment on mentions, the -i
option is not supported on BSD sed, and was therefore not used. See this comment for the sed variants I tested, though that may have been insufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could just avoid deleting the extra line? or use grep and only write the extra line if it doesn't exist already?
- It's important to delete the added line, because the
CMakeLists
file is part of the relic build, which is part of a submodule. The change to the submodule made here could end up in a (flow) commit very easily. - If we add the line only if it's not here already, the
tail
logic we use to grab theCC=...
line may fail (because a CC print may occur only earlier in the output), which may silently cause a divergence between cmake's notion of CC and that of the present script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree deleting the line would be cleaner, I just wanted to avoid using sed
.
The sed
command to delete the line works fine on my machine 👌
crypto/relic_build.sh
Outdated
mv $CMAKE_TEMP ../CMakeLists.txt | ||
|
||
# extract what cmake uses as CC and probe its version string | ||
CC_VAL="$(tail -n 5 "$CMAKE_OUTPUT" | grep -oE 'CC=.*$' | sed -re 's/CC=(.*)/\1/g')" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another use of sed
that might cause issues (it actually crashes on my macos).
We could just skip the 3 first characters instead of using sed
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's strange, I've tested this both on GNU sed v4.8, and OSX sed at on Big Sur (OS version 11.4).
What does sw_vers -productversion
say on your crashing system?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10.15.7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think sed -r
was the problem
crypto/relic_build.sh
Outdated
# extract what cmake uses as CC and probe its version string | ||
CC_VAL="$(tail -n 5 "$CMAKE_OUTPUT" | grep -oE 'CC=.*$' | sed -re 's/CC=(.*)/\1/g')" | ||
# default to which | ||
CC_VAL=${CC_VAL:-"$(which cc)"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a naive question : why don't we always rely on which cc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because that may not be the compiler used by cmake - it's a relatively primitive fallback. In particular:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I understand, that makes sense
I have implemented some of the suggestions, and also written the script in a way that looks easier to understand (at least to me) on this branch: https://github.com/onflow/flow-go/blob/tarak/arm-clang-relic-build/crypto/relic_build.sh. |
@tarakby I've integrated most of your changes, with a couple of tweaks:
|
d68fe49
to
6f058dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏄
6f058dc
to
44c8c48
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just some questions.
Detect if we're compiling on an ARM and drop the unsupported `-march=native` there. Fixes onflow#809.
44c8c48
to
606bcd5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
ShellCheck also 👍
Detect if we're compiling on an ARM and drop the unsupported
-march=native
there.Fixes #809