Skip to content

Commit

Permalink
Configure xcode build to link library
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed Mar 27, 2019
1 parent 389bef9 commit cf5cd8d
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 6 deletions.
57 changes: 57 additions & 0 deletions build-scripts/xc-universal-binary.sh
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -euvx

# This should be invoked from inside xcode, not manually
if [ "$#" -ne 4 ]
then
echo "Usage (note: only call inside xcode!):"
echo "Args: $*"
echo "path/to/build-scripts/xc-universal-binary.sh <STATIC_LIB_NAME> <FFI_TARGET> <APPSVC_ROOT_PATH> <buildvariant>"
exit 1
fi
# e.g. libglean_ffi.a
STATIC_LIB_NAME=$1
# what to pass to cargo build -p, e.g. glean_ffi
FFI_TARGET=$2
# path to app services root
APPSVC_ROOT=$3
# buildvariant from our xcconfigs
BUILDVARIANT=$4

RELFLAG=
RELDIR="debug"
if [[ "$BUILDVARIANT" != "debug" ]]; then
RELFLAG=--release
RELDIR=release
fi

TARGETDIR=$APPSVC_ROOT/target

# We can't use cargo lipo because we can't link to universal libraries :(
# https://github.com/rust-lang/rust/issues/55235
LIBS_ARCHS=("x86_64" "arm64")
IOS_TRIPLES=("x86_64-apple-ios" "aarch64-apple-ios")
for i in "${!LIBS_ARCHS[@]}"; do
LIB_ARCH=${LIBS_ARCHS[$i]}
env -i PATH="$PATH" \
$HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib $RELFLAG --target ${IOS_TRIPLES[$i]}
done

UNIVERSAL_BINARY=$TARGETDIR/universal/$RELDIR/$STATIC_LIB_NAME
NEED_LIPO=

# if the universal binary doesnt exist, or if it's older than the static libs,
# we need to run `lipo` again.
if [[ ! -f "$UNIVERSAL_BINARY" ]]; then
NEED_LIPO=1
elif [[ $(stat -f "%m" $TARGETDIR/x86_64-apple-ios/$RELDIR/$STATIC_LIB_NAME) -gt $(stat -f "%m" $UNIVERSAL_BINARY) ]]; then
NEED_LIPO=1
elif [[ $(stat -f "%m" $TARGETDIR/aarch64-apple-ios/$RELDIR/$STATIC_LIB_NAME) -gt $(stat -f "%m" $UNIVERSAL_BINARY) ]]; then
NEED_LIPO=1
fi
if [[ "$NEED_LIPO" = "1" ]]; then
mkdir -p $TARGETDIR/universal/$RELDIR
lipo -create -output "$UNIVERSAL_BINARY" \
$TARGETDIR/x86_64-apple-ios/$RELDIR/$STATIC_LIB_NAME \
$TARGETDIR/aarch64-apple-ios/$RELDIR/$STATIC_LIB_NAME
fi
67 changes: 61 additions & 6 deletions glean-core/ios/Glean.xcodeproj/project.pbxproj
Expand Up @@ -3,13 +3,18 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
BF3DE39B2243A2F20018E23F /* Glean.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF3DE3912243A2F20018E23F /* Glean.framework */; };
BF3DE3A02243A2F20018E23F /* GleanTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3DE39F2243A2F20018E23F /* GleanTests.swift */; };
BF3DE3A22243A2F20018E23F /* Glean.h in Headers */ = {isa = PBXBuildFile; fileRef = BF3DE3942243A2F20018E23F /* Glean.h */; settings = {ATTRIBUTES = (Public, ); }; };
BF51C3BC224BF19F0014CBAF /* common.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = BF51C3B8224BF19F0014CBAF /* common.xcconfig */; };
BF51C3BD224BF19F0014CBAF /* debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = BF51C3B9224BF19F0014CBAF /* debug.xcconfig */; };
BF51C3BE224BF19F0014CBAF /* release.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = BF51C3BA224BF19F0014CBAF /* release.xcconfig */; };
BF51C3BF224BF19F0014CBAF /* base.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = BF51C3BB224BF19F0014CBAF /* base.xcconfig */; };
BF6F2DA8224BF8F100394062 /* libglean_ffi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BF6F2DA7224BF8F100394062 /* libglean_ffi.a */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -29,13 +34,19 @@
BF3DE39A2243A2F20018E23F /* GleanTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GleanTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
BF3DE39F2243A2F20018E23F /* GleanTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GleanTests.swift; sourceTree = "<group>"; };
BF3DE3A12243A2F20018E23F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BF51C3B8224BF19F0014CBAF /* common.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = common.xcconfig; sourceTree = "<group>"; };
BF51C3B9224BF19F0014CBAF /* debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = debug.xcconfig; sourceTree = "<group>"; };
BF51C3BA224BF19F0014CBAF /* release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = release.xcconfig; sourceTree = "<group>"; };
BF51C3BB224BF19F0014CBAF /* base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = base.xcconfig; sourceTree = "<group>"; };
BF6F2DA7224BF8F100394062 /* libglean_ffi.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libglean_ffi.a; path = ../../target/universal/release/libglean_ffi.a; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
BF3DE38E2243A2F20018E23F /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
BF6F2DA8224BF8F100394062 /* libglean_ffi.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -53,9 +64,14 @@
BF3DE3872243A2F20018E23F = {
isa = PBXGroup;
children = (
BF51C3BB224BF19F0014CBAF /* base.xcconfig */,
BF51C3B8224BF19F0014CBAF /* common.xcconfig */,
BF51C3B9224BF19F0014CBAF /* debug.xcconfig */,
BF51C3BA224BF19F0014CBAF /* release.xcconfig */,
BF3DE3932243A2F20018E23F /* Glean */,
BF3DE39E2243A2F20018E23F /* GleanTests */,
BF3DE3922243A2F20018E23F /* Products */,
BF6F2DA6224BF8F000394062 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -86,6 +102,14 @@
path = GleanTests;
sourceTree = "<group>";
};
BF6F2DA6224BF8F000394062 /* Frameworks */ = {
isa = PBXGroup;
children = (
BF6F2DA7224BF8F100394062 /* libglean_ffi.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand All @@ -104,6 +128,7 @@
isa = PBXNativeTarget;
buildConfigurationList = BF3DE3A52243A2F20018E23F /* Build configuration list for PBXNativeTarget "Glean" */;
buildPhases = (
BF6F2DA5224BF2E000394062 /* ShellScript */,
BF3DE38C2243A2F20018E23F /* Headers */,
BF3DE38D2243A2F20018E23F /* Sources */,
BF3DE38E2243A2F20018E23F /* Frameworks */,
Expand Down Expand Up @@ -155,7 +180,7 @@
};
};
buildConfigurationList = BF3DE38B2243A2F20018E23F /* Build configuration list for PBXProject "Glean" */;
compatibilityVersion = "Xcode 9.3";
compatibilityVersion = "Xcode 10.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand All @@ -177,6 +202,10 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BF51C3BE224BF19F0014CBAF /* release.xcconfig in Resources */,
BF51C3BD224BF19F0014CBAF /* debug.xcconfig in Resources */,
BF51C3BC224BF19F0014CBAF /* common.xcconfig in Resources */,
BF51C3BF224BF19F0014CBAF /* base.xcconfig in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -189,6 +218,26 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
BF6F2DA5224BF2E000394062 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "bash $PWD/../../build-scripts/xc-universal-binary.sh libglean_ffi.a glean_ffi $PWD/../.. $buildvariant\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
BF3DE38D2243A2F20018E23F /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -340,11 +389,12 @@
};
BF3DE3A62243A2F20018E23F /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = BF51C3B9224BF19F0014CBAF /* debug.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Manual;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 99QSBDSJN4;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -357,6 +407,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.mozilla.Glean;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -365,11 +416,12 @@
};
BF3DE3A72243A2F20018E23F /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = BF51C3BA224BF19F0014CBAF /* release.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Manual;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 99QSBDSJN4;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -382,6 +434,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.mozilla.Glean;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -390,6 +443,7 @@
};
BF3DE3A92243A2F20018E23F /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = BF51C3B9224BF19F0014CBAF /* debug.xcconfig */;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 99QSBDSJN4;
Expand All @@ -408,6 +462,7 @@
};
BF3DE3AA2243A2F20018E23F /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = BF51C3BA224BF19F0014CBAF /* release.xcconfig */;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 99QSBDSJN4;
Expand Down
5 changes: 5 additions & 0 deletions glean-core/ios/base.xcconfig
@@ -0,0 +1,5 @@
#include "common.xcconfig"

INFOPLIST_FILE = Glean/Info.plist
LIBRARY_SEARCH_PATHS = "../../target/universal/$(buildvariant)"
SWIFT_OBJC_BRIDGING_HEADER = Glean/Glean.h
75 changes: 75 additions & 0 deletions glean-core/ios/common.xcconfig
@@ -0,0 +1,75 @@
SDKROOT = iphoneos
ONLY_ACTIVE_ARCH = YES
DEFINES_MODULE = YES
PRODUCT_NAME = $(TARGET_NAME:c99extidentifier)

CURRENT_PROJECT_VERSION = 1
VERSION_INFO_PREFIX =
VERSIONING_SYSTEM = apple-generic
TARGETED_DEVICE_FAMILY = 1,2
IPHONEOS_DEPLOYMENT_TARGET = 11.0
DYLIB_COMPATIBILITY_VERSION = 1
DYLIB_CURRENT_VERSION = 1
DYLIB_INSTALL_NAME_BASE = @rpath
LD_RUNPATH_SEARCH_PATHS = @executable_path/Frameworks @loader_path/Frameworks

SWIFT_VERSION = 4.0
ENABLE_BITCODE = NO

SWIFT_OPTIMIZATION_LEVEL_debug = -Onone
SWIFT_OPTIMIZATION_LEVEL_release = -O
SWIFT_OPTIMIZATION_LEVEL = $(SWIFT_OPTIMIZATION_LEVEL_$(buildvariant))

SWIFT_ACTIVE_COMPILATION_CONDITIONS_debug = DEBUG
SWIFT_ACTIVE_COMPILATION_CONDITIONS_release =
SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(SWIFT_ACTIVE_COMPILATION_CONDITIONS_$(buildvariant))

SWIFT_COMPILATION_MODE_debug =
SWIFT_COMPILATION_MODE_release = wholemodule
SWIFT_COMPILATION_MODE = $(SWIFT_COMPILATION_MODE_$(buildvariant))

ENABLE_TESTABILITY_debug = YES
ENABLE_TESTABILITY_release = NO
ENABLE_TESTABILITY = $(ENABLE_TESTABILITY_$(buildvariant))

GCC_OPTIMIZATION_LEVEL_debug = 0
GCC_OPTIMIZATION_LEVEL_release = s
GCC_OPTIMIZATION_LEVEL = $(GCC_OPTIMIZATION_LEVEL_$(buildvariant))

GCC_PREPROCESSOR_DEFINITIONS_debug = DEBUG=1
GCC_PREPROCESSOR_DEFINITIONS_release =
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_$(buildvariant))

GCC_DYNAMIC_NO_PIC = NO
GCC_NO_COMMON_BLOCKS = YES
GCC_C_LANGUAGE_STANDARD = gnu11
CLANG_CXX_LANGUAGE_STANDARD = gnu++14
CLANG_CXX_LIBRARY = libc++
CLANG_ENABLE_OBJC_ARC = YES
CLANG_ENABLE_OBJC_WEAK = YES
ENABLE_STRICT_OBJC_MSGSEND = YES

// Warnings
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES
CLANG_WARN_EMPTY_BODY = YES
CLANG_WARN_BOOL_CONVERSION = YES
CLANG_WARN_CONSTANT_CONVERSION = YES
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
CLANG_WARN_ENUM_CONVERSION = YES
CLANG_WARN_INT_CONVERSION = YES
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES
CLANG_WARN_INFINITE_RECURSION = YES
GCC_WARN_ABOUT_RETURN_TYPE = YES
CLANG_WARN_STRICT_PROTOTYPES = YES
CLANG_WARN_COMMA = YES
GCC_WARN_UNINITIALIZED_AUTOS = YES
CLANG_WARN_UNREACHABLE_CODE = YES
GCC_WARN_UNUSED_FUNCTION = YES
GCC_WARN_UNUSED_VARIABLE = YES
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES
CLANG_WARN_SUSPICIOUS_MOVE = YES
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES
GCC_WARN_UNDECLARED_SELECTOR = YES
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
2 changes: 2 additions & 0 deletions glean-core/ios/debug.xcconfig
@@ -0,0 +1,2 @@
buildvariant = debug
#include "base.xcconfig"
2 changes: 2 additions & 0 deletions glean-core/ios/release.xcconfig
@@ -0,0 +1,2 @@
buildvariant = release
#include "base.xcconfig"

0 comments on commit cf5cd8d

Please sign in to comment.