Skip to content

Commit

Permalink
Fix gradle builds for Apple Silicon running arm64 JDKs (#4792)
Browse files Browse the repository at this point in the history
* add the darwin-aarch64
* fix gradle builds for m1 macs using arm64 JDK
* updated verify desktop scripts to help people migrate
  • Loading branch information
skhamis authored Feb 3, 2022
1 parent 0818678 commit cbfa39d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildscript {
mockito_core_version = '2.28.2'
roboelectric_core_version = '4.5.1'
robolectric_core_version = '4.5.1'
rust_android_gradle_version = '0.8.3'
rust_android_gradle_version = '0.9.1'
espresso_core_version = '3.3.0'
protobuf_version = '3.11.4'
gradle_protobuf_version = '0.8.14'
Expand Down Expand Up @@ -61,7 +61,7 @@ buildscript {
// Publish.
classpath "digital.wup:android-maven-publish:$maven_publish_version"

classpath "gradle.plugin.org.mozilla.rust-android-gradle:plugin:$rust_android_gradle_version"
classpath "org.mozilla.rust-android-gradle:plugin:$rust_android_gradle_version"

// Yes, this is unusual. We want to access some host-specific
// computation at build time.
Expand Down Expand Up @@ -145,8 +145,8 @@ if (useDownloadedLibs) {
task downloadDesktopLibs(type: Download) {
src {
switch (DefaultPlatform.RESOURCE_PREFIX) {
case 'darwin':
case 'darwin-x86-64':
case 'darwin-aarch64':
return "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/project.application-services.application-services.build.libs.desktop.macos.${rootProject.ext.libsGitSha}/artifacts/public/build/macos.tar.gz"
case 'linux-x86-64':
return "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/project.application-services.application-services.build.libs.desktop.linux.${rootProject.ext.libsGitSha}/artifacts/public/build/linux.tar.gz"
Expand All @@ -162,8 +162,8 @@ if (useDownloadedLibs) {

dest {
switch (DefaultPlatform.RESOURCE_PREFIX) {
case 'darwin':
case 'darwin-x86-64':
case 'darwin-aarch64':
return new File(buildDir, "libs.desktop.macos.${rootProject.ext.libsGitSha}.tar.gz")
case 'linux-x86-64':
return new File(buildDir, "libs.desktop.linux.${rootProject.ext.libsGitSha}.tar.gz")
Expand Down Expand Up @@ -229,9 +229,11 @@ ext.rustTargets = [

// Generate libs for our current platform so we can run unit tests.
switch (DefaultPlatform.RESOURCE_PREFIX) {
case 'darwin':
case 'darwin-x86-64':
ext.nativeRustTarget = 'darwin'
ext.nativeRustTarget = 'darwin-x86-64'
break
case 'darwin-aarch64':
ext.nativeRustTarget = 'darwin-aarch64'
break
case 'linux-x86-64':
ext.nativeRustTarget = 'linux-x86-64'
Expand Down
3 changes: 2 additions & 1 deletion libs/build-nss-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ elif [[ -n "${CROSS_COMPILE_TARGET}" ]]; then
echo "Cannot build NSS for unrecognized target OS ${CROSS_COMPILE_TARGET}"
exit 1
elif [[ "$(uname -s)" == "Darwin" ]]; then
DIST_DIR=$(abspath "desktop/darwin/nss")
TARGET_OS="macos"
# We need to set this variable for switching libs based on different macos archs (M1 vs Intel)
if [[ "$(uname -m)" == "arm64" ]]; then
DIST_DIR=$(abspath "desktop/darwin-aarch64/nss")
TARGET_ARCH="aarch64"
else
DIST_DIR=$(abspath "desktop/darwin-x86-64/nss")
TARGET_ARCH="x86_64"
fi
elif [[ "$(uname -s)" == "Linux" ]]; then
Expand Down
6 changes: 4 additions & 2 deletions libs/build-sqlcipher-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ elif [[ -n "${CROSS_COMPILE_TARGET}" ]]; then
echo "Cannot build SQLCipher for unrecognized target OS ${CROSS_COMPILE_TARGET}"
exit 1
elif [[ "$(uname -s)" == "Darwin" ]]; then
DIST_DIR=$(abspath "desktop/darwin/sqlcipher")
NSS_DIR=$(abspath "desktop/darwin/nss")
TARGET_OS="macos"
# We need to set this variable for switching libs based on different macos archs (M1 vs Intel)
if [[ "$(uname -m)" == "arm64" ]]; then
TARGET_ARCH="aarch64"
DIST_DIR=$(abspath "desktop/darwin-aarch64/sqlcipher")
NSS_DIR=$(abspath "desktop/darwin-aarch64/nss")
else
TARGET_ARCH="x86_64"
DIST_DIR=$(abspath "desktop/darwin-x86-64/sqlcipher")
NSS_DIR=$(abspath "desktop/darwin-x86-64/nss")
fi
elif [[ "$(uname -s)" == "Linux" ]]; then
# This is a JNA weirdness: "x86-64" rather than "x86_64".
Expand Down
23 changes: 22 additions & 1 deletion libs/verify-desktop-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

set -e

YELLOW=$"\033[1;33m"
NC=$"\033[0m" # No Color

if [[ ! -f "$(pwd)/libs/build-all.sh" ]]; then
echo "ERROR: bootstrap-desktop.sh should be run from the root directory of the repo"
exit 1
Expand All @@ -14,7 +17,11 @@ fi
"$(pwd)/libs/verify-common.sh"

if [[ "$(uname -s)" == "Darwin" ]]; then
APPSERVICES_PLATFORM_DIR="$(pwd)/libs/desktop/darwin"
if [[ "$(uname -m)" == "arm64" ]]; then
APPSERVICES_PLATFORM_DIR="$(pwd)/libs/desktop/darwin-aarch64"
else
APPSERVICES_PLATFORM_DIR="$(pwd)/libs/desktop/darwin-x86-64"
fi
else
APPSERVICES_PLATFORM_DIR="$(pwd)/libs/desktop/linux-x86-64"
fi
Expand All @@ -30,6 +37,20 @@ if [[ -z "${SQLCIPHER_LIB_DIR}" ]] || [[ -z "${SQLCIPHER_INCLUDE_DIR}" ]] || [[
exit 1
fi

# If users previously have built NSS their env vars will still be pointing to darwin
# we need to tell them to update their env with the new arch-specific style
if [[ -z "${CI}" ]] && [[ "$(uname -s)" == "Darwin" ]] && [[ "${NSS_DIR}" != *"desktop/darwin-"* ]]; then
echo ""
echo -e "${YELLOW}!! Your environment variables are outdated! Please use the updated values below !!"
echo -e "Please export or add to your shell initialization file (.zshenv, .bashrc etc.) the following ${NC}"
echo ""
echo "export SQLCIPHER_LIB_DIR=${APPSERVICES_PLATFORM_DIR}/sqlcipher/lib"
echo "export SQLCIPHER_INCLUDE_DIR=${APPSERVICES_PLATFORM_DIR}/sqlcipher/include"
echo "export NSS_DIR=${APPSERVICES_PLATFORM_DIR}/nss"
echo "export NSS_STATIC=1"
exit 1
fi

if [[ ! -d "${SQLCIPHER_LIB_DIR}" ]] || [[ ! -d "${NSS_DIR}" ]]; then
pushd libs
./build-all.sh desktop
Expand Down

0 comments on commit cbfa39d

Please sign in to comment.