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

Compiling libfido in macOS bigSur - apple silicon chip. #274

Closed
iradization opened this issue Feb 10, 2021 · 5 comments
Closed

Compiling libfido in macOS bigSur - apple silicon chip. #274

iradization opened this issue Feb 10, 2021 · 5 comments
Labels
question Further information is requested

Comments

@iradization
Copy link

Hi, I'm trying to compile the libfido project for macOS environment with apple silicon (arm64)

According to the documentation, it should be performed in the following command, but I think there are some prerequisites that are unmentioned ...

This is my attempt

libfido2-1.6.0 % (rm -rf build && mkdir build && cd build && cmake ..)

-- The C compiler identification is AppleClang 12.0.0.12000032
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
-- Checking for one of the modules 'libcbor'
-- Checking for one of the modules 'libcrypto'
-- Looking for include file cbor.h
-- Looking for include file cbor.h - not found
CMake Error at CMakeLists.txt:97 (message):
  could not find cbor header files

from cmake source, I fell on the following code :

        if(NOT CBOR_FOUND)
                check_include_files(cbor.h HAVE_CBOR_H)
                if(NOT HAVE_CBOR_H)
                        message(FATAL_ERROR "could not find cbor header files")
                endif()
                set(CBOR_LIBRARIES "cbor")
        endif()

Not sure where exactly where should I put cbor.h relative to libfido main folder ?
Does it have other pre-requirements besides that ?

@martelletto
Copy link
Contributor

Hi,

The easiest way is to install pkg-config, libcbor, and OpenSSL using Homebrew and set the PKG_CONFIG_PATH environment varable:

$ brew install pkg-config libcbor openssl
$ export PKG_CONFIG_PATH="$(brew --prefix openssl@1.1)/lib/pkgconfig"
$ (rm -rf build && mkdir build && cd build && cmake ..)

This is the approach currently implemented in .actions/build-osx-clang. According to https://formulae.brew.sh/, the required dependencies are available on Apple Silicon (and so is libfido2 itself).

If Homebrew is not an option, you will probably need to install libcbor and OpenSSL by hand. Let me know if that's the case and I will happily help you out.

-p.

@iradization
Copy link
Author

Hi @martelletto and thanks for your guidance it resolve my problem. I also prefer, as you suggested, to compile the dependencies manually, completely independent from intermediators like brew - perhaps you can provide me some guidance in this area as well ? Perhaps it can be added to build-osx-clang ?

thanks

@martelletto
Copy link
Contributor

Hi,

A variation of these steps should work:

  • Prepare the ground:
$ mkdir -p staging/root staging/src
$ export FAKEROOT="$(realpath staging/root)"
$ cd staging/src
$ git clone --branch OpenSSL_1_1_1i https://github.com/openssl/openssl
$ git clone --branch v0.8.0 https://github.com/pjk/libcbor
$ git clone --branch 1.6.0 https://github.com/yubico/libfido2
  • Build and install OpenSSL:
$ cd openssl
$ ./Configure darwin64-x86_64-cc --prefix="${FAKEROOT}" --openssldir="${FAKEROOT}/openssl"
$ make install_sw

You will probably want to adjust the target from darwin64-x86_64-cc to that of Apple Silicon.

  • Build and install libcbor:
$ cd ../libcbor
$ mkdir build
$ cd build
$ cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX="${FAKEROOT}" -DCMAKE_INSTALL_NAME_DIR="${FAKEROOT}/lib"
$ make VERBOSE=1 all install
  • Build and install libfido2:
$ cd ../../libfido2
$ mkdir build
$ cd build
$ export CFLAGS="-I${FAKEROOT}/include"
$ export LDFLAGS="-L${FAKEROOT}/lib"
$ cmake -DCMAKE_INSTALL_PREFIX="${FAKEROOT}" ..
$ make
$ make install
  • Check that the installation looks ok:
$ "${FAKEROOT}/bin/fido2-token" -V
1.6.0

Cheers,

-p.

@iradization
Copy link
Author

iradization commented Feb 14, 2021

Thanks @martelletto, it's working great. I was also thinking about building the libraries in FAT format so I can use it on both platforms (x86_64 and arm64).

Does libfido2 support this capability (building on both arch from M1 computer) or I should build it separately in each platform and merge them to FAT using lipo?

@martelletto
Copy link
Contributor

No idea. :) In principle it should work.

@martelletto martelletto added the question Further information is requested label Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

2 participants