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

Fix cross-compilation on macOS with SDK and ARCH #849

Merged
merged 4 commits into from
Jun 30, 2021

Conversation

ilammy
Copy link
Collaborator

@ilammy ilammy commented Jun 29, 2021

Surprisingly, it's possible to cross-compile Themis Core for different SDKs and architectures using our makefile. For example,

make SDK=macosx11.0 ARCH=arm64

will compile for Apple Silicon, provided that your Xcode toolchain is actually capable of building that architecture.

You also need to have OpenSSL binaries with desired architecture installed (for which you might need to tweak ENGINE_INCLUDE_PATH and ENGINE_LIB_PATH separately). Or build ENGINE=boringssl to use embedded BoringSSL that we can cross-compile too.

There were some missing bits here and there to make it work, but now it works. See commit messages for details.

Checklist

  • Change is covered by automated tests
  • The coding guidelines are followed
  • Changelog is updated (in case of notable or breaking changes)

Surprisingly, it's possible to cross-compile Themis Core for different
SDKs and architectures using our makefile. For example,

    make SDK=macosx11.0 ARCH=arm64

will compile for Apple Silicon, provided that your Xcode toolchain is
actually capable of building that architecture.

You also need to have OpenSSL binaries with desired architecture
installed (for which you might need to tweak ENGINE_INCLUDE_PATH and
ENGINE_LIB_PATH separately). Or build ENGINE=boringssl to use embedded
BoringSSL that we can cross-compile too.

However, cross-compilation does not work because the architecture and
system library directries are not set at link time, so libthemis.dylib
it attempted to be linked for the native target which does not work.

Pass proper settings to LDFLAGS at configuration time so that
cross-compilation has a chance to work.
If we seem to be cross-compiling, tell CMake what SDK it should use and
what architecture it should be building. It knows what to do next.
Throw in a job to make sure that cross-compilations stays in working
order. Unfortunately, we can't actually run unit tests, but hey, at
least it compiles.
@ilammy ilammy added core Themis Core written in C, its packages O-macOS 💻 Operating system: macOS C-BoringSSL Crypto provider: BoringSSL labels Jun 29, 2021
Copy link
Contributor

@vixentael vixentael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprise-surprise..

Thank you @ilammy <3

- name: Check binary architecture
run: |
set -x
test $(lipo -archs build/libsoter.0.dylib) = arm64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hah, that's clever!

@ilammy ilammy merged commit edcd50c into cossacklabs:master Jun 30, 2021
@ilammy ilammy deleted the macos-cross branch June 30, 2021 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-BoringSSL Crypto provider: BoringSSL core Themis Core written in C, its packages O-macOS 💻 Operating system: macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants