Skip to content

Commit

Permalink
Merge pull request #1498 from badboy/ios-sim
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy authored Feb 24, 2021
2 parents 14666b0 + a615995 commit a7b9670
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
10 changes: 8 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ jobs:
name: Setup build environment
command: |
rustup target add aarch64-apple-ios x86_64-apple-ios
cargo install cargo-lipo
# Bootstrap dependencies
bin/bootstrap.sh
Expand Down Expand Up @@ -644,12 +643,19 @@ jobs:
name: Setup build environment
command: |
rustup target add aarch64-apple-ios x86_64-apple-ios
cargo install cargo-lipo
# List available devices -- allows us to see what's there
xcrun instruments -w list || true
# See https://circleci.com/docs/2.0/testing-ios/#pre-starting-the-simulator
xcrun instruments -w "iPhone 11 (14" || true
- run:
name: Install Rust Nightly toolchain
command: |
# Need a nightly toolchain and the source code for targetting the arm64 iOS simulator
# We don't need that build on CI, but its hard to exclude it from the build
# while still allowing it in developer builds.
rustup toolchain add nightly --profile minimal
rustup component add rust-src --toolchain nightly
- run:
name: Use current commit of Glean
command: |
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 34 additions & 27 deletions build-scripts/xc-universal-binary.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@
#!/usr/bin/env bash

# This should be invoked from inside xcode, not manually
if [ "$#" -ne 2 ]
if [ "$#" -ne 3 ]
then
echo "Usage (note: only call inside xcode!):"
echo "Args: $*"
echo "path/to/build-scripts/xc-universal-binary.sh <FFI_TARGET> <GLEAN_ROOT_PATH>"
echo "path/to/build-scripts/xc-universal-binary.sh <FFI_TARGET> <GLEAN_ROOT_PATH> <buildvariant>"
exit 1
fi

# what to pass to cargo build -p, e.g. glean_ffi
FFI_TARGET=$1
# path to app services root
GLEAN_ROOT=$2
# buildvariant from our xcconfigs
BUILDVARIANT=$3

if [ -d "$HOME/.cargo/bin" ]; then
export PATH="$HOME/.cargo/bin:$PATH"
RELFLAG=
if [[ "$BUILDVARIANT" != "debug" ]]; then
RELFLAG=--release
fi

if ! command -v cargo-lipo 2>/dev/null >/dev/null;
then
echo "$(basename $0) failed."
echo "Requires cargo-lipo to build universal library."
echo "Install it with:"
echo
echo " cargo install cargo-lipo"
exit 1
fi

# Ease testing of this script by assuming something about the environment.
if [ -z "$ACTION" ]; then
export ACTION=build
fi

# Always build both architectures on x86_64.
export ARCHS="arm64 x86_64"

set -euvx

if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then
Expand All @@ -46,9 +31,31 @@ if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then
export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}"
fi

# Force correct target for dependencies compiled with `cc`.
# Required for M1 MacBooks (Arm target).
# Without this some dependencies might be compiled for the wrong target.
export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios"
IS_SIMULATOR=0
if [ "${LLVM_TARGET_TRIPLE_SUFFIX-}" = "-simulator" ]; then
IS_SIMULATOR=1
fi

cargo lipo --xcode-integ --manifest-path "$GLEAN_ROOT/Cargo.toml" --package "$FFI_TARGET"
for arch in $ARCHS; do
case "$arch" in
x86_64)
if [ $IS_SIMULATOR -eq 0 ]; then
echo "Building for x86_64, but not a simulator build. What's going on?" >&2
exit 2
fi

# Intel iOS simulator
export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios"
$HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib $RELFLAG --target x86_64-apple-ios
;;

arm64)
if [ $IS_SIMULATOR -eq 0 ]; then
# Hardware iOS targets
$HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib $RELFLAG --target aarch64-apple-ios
else
# M1 iOS simulator -- currently in Nightly only and requires to build `libstd`
$HOME/.cargo/bin/cargo +nightly build -Z build-std -p $FFI_TARGET --lib $RELFLAG --target aarch64-apple-ios-sim
fi
esac
done
10 changes: 7 additions & 3 deletions glean-core/ios/Glean.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "bash $PWD/../../build-scripts/xc-universal-binary.sh glean-ffi $PWD/../..\n";
shellScript = "bash $PWD/../../build-scripts/xc-universal-binary.sh glean-ffi $PWD/../.. $buildvariant\n";
};
BFB59A9723429FC000F40CA8 /* Run Glean SDK generator */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -766,7 +766,6 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Glean/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -775,6 +774,9 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
"LIBRARY_SEARCH_PATHS[sdk=iphoneos*][arch=arm64]" = "../../target/aarch64-apple-ios/debug";
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=arm64]" = "../../target/aarch64-apple-ios-sim/debug";
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=x86_64]" = "../../target/x86_64-apple-ios/debug";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.mozilla.Glean;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand All @@ -800,7 +802,6 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Glean/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -809,6 +810,9 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
"LIBRARY_SEARCH_PATHS[sdk=iphoneos*][arch=arm64]" = "../../target/aarch64-apple-ios/release";
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=arm64]" = "../../target/aarch64-apple-ios-sim/release";
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=x86_64]" = "../../target/x86_64-apple-ios/release";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.mozilla.Glean;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down
1 change: 0 additions & 1 deletion glean-core/ios/base.xcconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "../../xcconfig/common.xcconfig"

INFOPLIST_FILE = Glean/Info.plist
LIBRARY_SEARCH_PATHS = "../../target/universal/$(buildvariant)"
2 changes: 0 additions & 2 deletions samples/ios/app/glean-sample-app.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = G9EAK7RA89;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
FRAMEWORK_SEARCH_PATHS = "";
INFOPLIST_FILE = "glean-sample-app/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -564,7 +563,6 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = G9EAK7RA89;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
FRAMEWORK_SEARCH_PATHS = "";
INFOPLIST_FILE = "glean-sample-app/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
Expand Down

0 comments on commit a7b9670

Please sign in to comment.