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

OpenSSL detection on OSX #399

Closed
msprotz opened this issue Apr 17, 2023 · 4 comments · Fixed by #403
Closed

OpenSSL detection on OSX #399

msprotz opened this issue Apr 17, 2023 · 4 comments · Fixed by #403

Comments

@msprotz
Copy link
Collaborator

msprotz commented Apr 17, 2023

After following the various suggestions for ./mach benchmark, I ended up with this:

jonathan@absinthe:~/Code/hacl-packages (main) $ ./mach build --benchmark
 [mach] ! Benchmarks need to be run on release for now. Please add --release
jonathan@absinthe:~/Code/hacl-packages (main) $ ./mach build --benchmark --release
 [mach] Using config/config.json to configure ...
 [mach] Writing cmake config to build/config.cmake ...
 [mach] Collecting files and dependencies ...
-- Bug 81300 check: FALSE
-- int128 support: TRUE
-- explicit_bzero support: FALSE
-- vec128 support: TRUE
-- vec256 support: TRUE
-- LINUX_NO_EXPLICIT_BZERO: 1
-- Detected vale support
-- Detected intrinsics support
-- Detected an x64 architecture
-- Building benchmarks
-- Found Python: /usr/local/Frameworks/Python.framework/Versions/3.11/bin/python3.11 (found version "3.11.2") found components: Interpreter 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Populating benchmark
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jonathan/Code/hacl-packages/build/benchmark-subbuild
[1/9] Creating directories for 'benchmark-populate'
[1/9] Performing download step (git clone) for 'benchmark-populate'
Cloning into 'benchmark-src'...
HEAD is now at 361e8d1 version bump
[2/9] Performing update step for 'benchmark-populate'
[3/9] No patch step for 'benchmark-populate'
[5/9] No configure step for 'benchmark-populate'
[6/9] No build step for 'benchmark-populate'
[7/9] No install step for 'benchmark-populate'
[8/9] No test step for 'benchmark-populate'
[9/9] Completed 'benchmark-populate'
-- Failed to find LLVM FileCheck
-- Found Git: /usr/local/bin/git (found version "2.38.1") 
-- git version: v1.7.0 normalized to 1.7.0
-- Version: 1.7.0
-- Looking for shm_open in rt
-- Looking for shm_open in rt - not found
-- Performing Test HAVE_CXX_FLAG_STD_CXX11
-- Performing Test HAVE_CXX_FLAG_STD_CXX11 - Success
-- Performing Test HAVE_CXX_FLAG_WALL
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WSHADOW
-- Performing Test HAVE_CXX_FLAG_WSHADOW - Success
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL - Success
-- Performing Test HAVE_CXX_FLAG_WERROR
-- Performing Test HAVE_CXX_FLAG_WERROR - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC
-- Performing Test HAVE_CXX_FLAG_PEDANTIC - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS - Success
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32 - Success
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED_DECLARATIONS
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED_DECLARATIONS - Success
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED - Success
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WD654
-- Performing Test HAVE_CXX_FLAG_WD654 - Failed
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY - Success
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- failed to compile: Change Dir: /Users/jonathan/Code/hacl-packages/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/local/bin/ninja cmTC_33281 && [1/2] Building CXX object CMakeFiles/cmTC_33281.dir/Debug/thread_safety_attributes.cpp.o
FAILED: CMakeFiles/cmTC_33281.dir/Debug/thread_safety_attributes.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCMAKE_INTDIR=\"Debug\"  -std=c++11  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -Wthread-safety  -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -MD -MT CMakeFiles/cmTC_33281.dir/Debug/thread_safety_attributes.cpp.o -MF CMakeFiles/cmTC_33281.dir/Debug/thread_safety_attributes.cpp.o.d -o CMakeFiles/cmTC_33281.dir/Debug/thread_safety_attributes.cpp.o -c /Users/jonathan/Code/hacl-packages/build/benchmark-src/cmake/thread_safety_attributes.cpp
In file included from /Users/jonathan/Code/hacl-packages/build/benchmark-src/cmake/thread_safety_attributes.cpp:2:
In file included from /Users/jonathan/Code/hacl-packages/build/benchmark-src/cmake/../src/mutex.h:7:
/Users/jonathan/Code/hacl-packages/build/benchmark-src/cmake/../src/check.h:8:10: fatal error: 'benchmark/export.h' file not found
#include "benchmark/export.h"
         ^~~~~~~~~~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.


-- Performing Test HAVE_CXX_FLAG_COVERAGE
-- Performing Test HAVE_CXX_FLAG_COVERAGE - Success
-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX -- success
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile: Change Dir: /Users/jonathan/Code/hacl-packages/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/local/bin/ninja cmTC_219fd && [1/2] Building CXX object CMakeFiles/cmTC_219fd.dir/Debug/gnu_posix_regex.cpp.o
FAILED: CMakeFiles/cmTC_219fd.dir/Debug/gnu_posix_regex.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCMAKE_INTDIR=\"Debug\"  -std=c++11  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -Wthread-safety  -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -MD -MT CMakeFiles/cmTC_219fd.dir/Debug/gnu_posix_regex.cpp.o -MF CMakeFiles/cmTC_219fd.dir/Debug/gnu_posix_regex.cpp.o.d -o CMakeFiles/cmTC_219fd.dir/Debug/gnu_posix_regex.cpp.o -c /Users/jonathan/Code/hacl-packages/build/benchmark-src/cmake/gnu_posix_regex.cpp
/Users/jonathan/Code/hacl-packages/build/benchmark-src/cmake/gnu_posix_regex.cpp:1:10: fatal error: 'gnuregex.h' file not found
#include <gnuregex.h>
         ^~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.


-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK
-- Performing Test HAVE_STEADY_CLOCK
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Performing Test BENCHMARK_HAS_O3_FLAG
-- Performing Test BENCHMARK_HAS_O3_FLAG - Success
-- Performing Test BENCHMARK_HAS_WNO_ODR
-- Performing Test BENCHMARK_HAS_WNO_ODR - Success
-- Performing Test BENCHMARK_HAS_WNO_LTO_TYPE_MISMATCH
-- Performing Test BENCHMARK_HAS_WNO_LTO_TYPE_MISMATCH - Failed
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jonathan/Code/hacl-packages/build
ninja: Entering directory `build'
[155/293] Building CXX object CMakeFiles/chacha20_benchmark.dir/Release/benchmarks/chacha20.cc.o
FAILED: CMakeFiles/chacha20_benchmark.dir/Release/benchmarks/chacha20.cc.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCMAKE_INTDIR=\"Release\" -I/Users/jonathan/Code/hacl-packages/include -I/Users/jonathan/Code/hacl-packages/build -I/Users/jonathan/Code/hacl-packages/karamel/include -I/Users/jonathan/Code/hacl-packages/karamel/krmllib/dist/minimal -I/Users/jonathan/Code/hacl-packages/vale/include -I/Users/jonathan/Code/everest/MLCrypto/openssl/include -I/Users/jonathan/Code/hacl-packages/cpu-features/include -I/Users/jonathan/Code/hacl-packages/build/benchmark-src/include -I/Users/jonathan/Code/hacl-packages/build/benchmark-build/include -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -O3 -DHACL_CAN_COMPILE_VEC128 -DHACL_CAN_COMPILE_VEC256 -std=c++17 -MD -MT CMakeFiles/chacha20_benchmark.dir/Release/benchmarks/chacha20.cc.o -MF CMakeFiles/chacha20_benchmark.dir/Release/benchmarks/chacha20.cc.o.d -o CMakeFiles/chacha20_benchmark.dir/Release/benchmarks/chacha20.cc.o -c /Users/jonathan/Code/hacl-packages/benchmarks/chacha20.cc
/Users/jonathan/Code/hacl-packages/benchmarks/chacha20.cc:194:18: error: use of undeclared identifier 'EVP_EncryptInit_ex2'; did you mean 'EVP_EncryptInit_ex'?
    int result = EVP_EncryptInit_ex2(
                 ^~~~~~~~~~~~~~~~~~~
                 EVP_EncryptInit_ex
/Users/jonathan/Code/everest/MLCrypto/openssl/include/openssl/evp.h:573:16: note: 'EVP_EncryptInit_ex' declared here
/*__owur*/ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,
               ^
/Users/jonathan/Code/hacl-packages/benchmarks/chacha20.cc:195:28: error: cannot initialize a parameter of type 'ENGINE *' (aka 'engine_st *') with an rvalue of type 'std::vector<unsigned char>::value_type *' (aka 'unsigned char *')
      ctx, EVP_chacha20(), key.data(), openssl_nonce.data(), NULL);
                           ^~~~~~~~~~
/Users/jonathan/Code/everest/MLCrypto/openssl/include/openssl/evp.h:574:69: note: passing argument to parameter 'impl' here
                                  const EVP_CIPHER *cipher, ENGINE *impl,
                                                                    ^
2 errors generated.
[156/293] Building CXX object CMakeFiles/ed25519_benchmark.dir/Release/benchmarks/ed25519.cc.o
FAILED: CMakeFiles/ed25519_benchmark.dir/Release/benchmarks/ed25519.cc.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCMAKE_INTDIR=\"Release\" -I/Users/jonathan/Code/hacl-packages/include -I/Users/jonathan/Code/hacl-packages/build -I/Users/jonathan/Code/hacl-packages/karamel/include -I/Users/jonathan/Code/hacl-packages/karamel/krmllib/dist/minimal -I/Users/jonathan/Code/hacl-packages/vale/include -I/Users/jonathan/Code/everest/MLCrypto/openssl/include -I/Users/jonathan/Code/hacl-packages/cpu-features/include -I/Users/jonathan/Code/hacl-packages/build/benchmark-src/include -I/Users/jonathan/Code/hacl-packages/build/benchmark-build/include -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -O3 -DHACL_CAN_COMPILE_VEC128 -DHACL_CAN_COMPILE_VEC256 -std=c++17 -MD -MT CMakeFiles/ed25519_benchmark.dir/Release/benchmarks/ed25519.cc.o -MF CMakeFiles/ed25519_benchmark.dir/Release/benchmarks/ed25519.cc.o.d -o CMakeFiles/ed25519_benchmark.dir/Release/benchmarks/ed25519.cc.o -c /Users/jonathan/Code/hacl-packages/benchmarks/ed25519.cc
/Users/jonathan/Code/hacl-packages/benchmarks/ed25519.cc:56:5: error: use of undeclared identifier 'EVP_PKEY_new_raw_private_key'
    EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519, NULL, sk.data(), sk.size());
    ^
/Users/jonathan/Code/hacl-packages/benchmarks/ed25519.cc:98:5: error: use of undeclared identifier 'EVP_PKEY_new_raw_private_key'
    EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519, NULL, sk.data(), sk.size());
    ^
/Users/jonathan/Code/hacl-packages/benchmarks/ed25519.cc:108:3: error: use of undeclared identifier 'EVP_PKEY_get_raw_public_key'
  EVP_PKEY_get_raw_public_key(skey, pkey_raw.data(), &pkey_len);
  ^
/Users/jonathan/Code/hacl-packages/benchmarks/ed25519.cc:110:20: error: use of undeclared identifier 'EVP_PKEY_new_raw_public_key'; did you mean 'EVP_PKEY_new_mac_key'?
  EVP_PKEY* pkey = EVP_PKEY_new_raw_public_key(
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
                   EVP_PKEY_new_mac_key
/Users/jonathan/Code/everest/MLCrypto/openssl/include/openssl/evp.h:1334:11: note: 'EVP_PKEY_new_mac_key' declared here
EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e,
          ^
4 errors generated.
[161/293] Building CXX object CMakeFiles/chacha20poly1305_benchmark.dir/Release/benchmarks/chacha20poly1305.cc.o
FAILED: CMakeFiles/chacha20poly1305_benchmark.dir/Release/benchmarks/chacha20poly1305.cc.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCMAKE_INTDIR=\"Release\" -I/Users/jonathan/Code/hacl-packages/include -I/Users/jonathan/Code/hacl-packages/build -I/Users/jonathan/Code/hacl-packages/karamel/include -I/Users/jonathan/Code/hacl-packages/karamel/krmllib/dist/minimal -I/Users/jonathan/Code/hacl-packages/vale/include -I/Users/jonathan/Code/everest/MLCrypto/openssl/include -I/Users/jonathan/Code/hacl-packages/cpu-features/include -I/Users/jonathan/Code/hacl-packages/build/benchmark-src/include -I/Users/jonathan/Code/hacl-packages/build/benchmark-build/include -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -O3 -DHACL_CAN_COMPILE_VEC128 -DHACL_CAN_COMPILE_VEC256 -std=c++17 -MD -MT CMakeFiles/chacha20poly1305_benchmark.dir/Release/benchmarks/chacha20poly1305.cc.o -MF CMakeFiles/chacha20poly1305_benchmark.dir/Release/benchmarks/chacha20poly1305.cc.o.d -o CMakeFiles/chacha20poly1305_benchmark.dir/Release/benchmarks/chacha20poly1305.cc.o -c /Users/jonathan/Code/hacl-packages/benchmarks/chacha20poly1305.cc
/Users/jonathan/Code/hacl-packages/benchmarks/chacha20poly1305.cc:234:18: error: use of undeclared identifier 'EVP_EncryptInit_ex2'; did you mean 'EVP_EncryptInit_ex'?
    int result = EVP_EncryptInit_ex2(
                 ^~~~~~~~~~~~~~~~~~~
                 EVP_EncryptInit_ex
/Users/jonathan/Code/everest/MLCrypto/openssl/include/openssl/evp.h:573:16: note: 'EVP_EncryptInit_ex' declared here
/*__owur*/ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,
               ^
/Users/jonathan/Code/hacl-packages/benchmarks/chacha20poly1305.cc:235:37: error: cannot initialize a parameter of type 'ENGINE *' (aka 'engine_st *') with an rvalue of type 'std::vector<unsigned char>::value_type *' (aka 'unsigned char *')
      ctx, EVP_chacha20_poly1305(), key.data(), nonce.data(), NULL);
                                    ^~~~~~~~~~
/Users/jonathan/Code/everest/MLCrypto/openssl/include/openssl/evp.h:574:69: note: passing argument to parameter 'impl' here
                                  const EVP_CIPHER *cipher, ENGINE *impl,
                                                                    ^
2 errors generated.
[172/293] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/Release/src/gmock-all.cc.o
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "/Users/jonathan/Code/hacl-packages/./mach", line 493, in <module>
    main()
  File "/Users/jonathan/Code/hacl-packages/./mach", line 489, in main
    args.func(args)
  File "/Users/jonathan/Code/hacl-packages/./mach", line 423, in build
    subprocess.run(ninja_cmd, check=True)
  File "/usr/local/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ninja', '-f', 'build-Release.ninja', '-C', 'build']' returned non-zero exit status 1.

It looks like the build picked up on my OPENSSL_HOME environment variable. I tried again with OPENSSL_HOME=, but this time got:

FAILED: CMakeFiles/p256_benchmark.dir/Release/benchmarks/p256.cc.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCMAKE_INTDIR=\"Release\" -I/Users/jonathan/Code/hacl-packages/include -I/Users/jonathan/Code/hacl-packages/build -I/Users/jonathan/Code/hacl-packages/karamel/include -I/Users/jonathan/Code/hacl-packages/karamel/krmllib/dist/minimal -I/Users/jonathan/Code/hacl-packages/vale/include -I/Users/jonathan/Code/hacl-packages/cpu-features/include -I/Users/jonathan/Code/hacl-packages/build/benchmark-src/include -I/Users/jonathan/Code/hacl-packages/build/benchmark-build/include -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -O3 -DHACL_CAN_COMPILE_VEC128 -DHACL_CAN_COMPILE_VEC256 -std=c++17 -MD -MT CMakeFiles/p256_benchmark.dir/Release/benchmarks/p256.cc.o -MF CMakeFiles/p256_benchmark.dir/Release/benchmarks/p256.cc.o.d -o CMakeFiles/p256_benchmark.dir/Release/benchmarks/p256.cc.o -c /Users/jonathan/Code/hacl-packages/benchmarks/p256.cc
In file included from /Users/jonathan/Code/hacl-packages/benchmarks/p256.cc:8:
/Users/jonathan/Code/hacl-packages/benchmarks/util.h:9:10: fatal error: 'openssl/ec.h' file not found
#include <openssl/ec.h>
         ^~~~~~~~~~~~~~
1 error generated.

Any advice on what I can do to run the benchmarks on OSX?

Thanks!

@franziskuskiefer
Copy link
Member

By default the benchmarks are built for openssl as well. macOS doesn't ship with openssl 3 yet, which we require.
There's documentation for this in the book. But maybe we should put this somewhere more prominent.
The short answer is, set OPENSSL_HOME to the path of your openssl 3, or use --no-openssl to disable the openssl benchmarks.

@karthikbhargavan
Copy link
Collaborator

karthikbhargavan commented Apr 18, 2023

I compile OpenSSL from source and OpenSSL's make install puts it in /usr/local/* so I set OPENSSL_HOME=/usr/local. Homebrew puts OpenSSL@3 in /opt/... so you'll need to set OPENSSL_HOME accordingly.

@msprotz
Copy link
Collaborator Author

msprotz commented Apr 18, 2023

Ah great. I already have openssl3 at /usr/local/Cellar/openssl@3/ so it should just be a matter of exporting the right path. Thanks!

@msprotz
Copy link
Collaborator Author

msprotz commented Apr 18, 2023

Feel free to close this, or to change it to something more descriptive, such as "attempt to auto-detect openssl3 on OSX when installed via brew". In HACL*, I automatically pick up the location of openssl by doing this:

ifeq ($(shell uname),Darwin)
OPENSSL_ROOT=$(shell which brew >/dev/null && brew info --quiet openssl | egrep '^/' | cut -f 1 -d ' ')
ifneq (,$(OPENSSL_ROOT))
CFLAGS := -I$(OPENSSL_ROOT)/include/ $(CFLAGS)
LDFLAGS:= -L$(OPENSSL_ROOT)/lib $(LDFLAGS)
endif
endif

so it might be beneficial to do the same here, if the user hasn't picked anything specific for OPENSSL_HOME

@franziskuskiefer franziskuskiefer changed the title Cannot build benchmarks on default OSX OpenSSL detection on OSX Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants