UNPKG

2.55 kBapplication/x-shView Raw
1#!/bin/bash
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3#
4# This source code is licensed under the MIT license found in the
5# LICENSE file in the root directory of this source tree.
6
7set -e
8
9PLATFORM_NAME="${PLATFORM_NAME:-iphoneos}"
10CURRENT_ARCH="${CURRENT_ARCH}"
11
12if [ -z "$CURRENT_ARCH" ] || [ "$CURRENT_ARCH" == "undefined_arch" ]; then
13 # Xcode 10 beta sets CURRENT_ARCH to "undefined_arch", this leads to incorrect linker arg.
14 # it's better to rely on platform name as fallback because architecture differs between simulator and device
15
16 if [[ "$PLATFORM_NAME" == *"simulator"* ]]; then
17 CURRENT_ARCH="x86_64"
18 else
19 CURRENT_ARCH="arm64"
20 fi
21fi
22
23# @lint-ignore-every TXT2 Tab Literal
24if [ "$CURRENT_ARCH" == "arm64" ]; then
25 cat <<\EOF >>fix_glog_0.3.5_apple_silicon.patch
26diff --git a/config.sub b/config.sub
27index 1761d8b..43fa2e8 100755
28--- a/config.sub
29+++ b/config.sub
30@@ -1096,6 +1096,9 @@ case $basic_machine in
31 basic_machine=z8k-unknown
32 os=-sim
33 ;;
34+ arm64-*)
35+ basic_machine=$(echo $basic_machine | sed 's/arm64/aarch64/')
36+ ;;
37 none)
38 basic_machine=none-none
39 os=-none
40EOF
41
42 patch -p1 config.sub fix_glog_0.3.5_apple_silicon.patch
43fi
44
45export CC="$(xcrun -find -sdk $PLATFORM_NAME cc) -arch $CURRENT_ARCH -isysroot $(xcrun -sdk $PLATFORM_NAME --show-sdk-path)"
46export CXX="$CC"
47
48# Remove automake symlink if it exists
49if [ -h "test-driver" ]; then
50 rm test-driver
51fi
52
53# Manually disable gflags include to fix issue https://github.com/facebook/react-native/issues/28446
54sed -i.bak -e 's/\@ac_cv_have_libgflags\@/0/' src/glog/logging.h.in && rm src/glog/logging.h.in.bak
55sed -i.bak -e 's/HAVE_LIB_GFLAGS/HAVE_LIB_GFLAGS_DISABLED/' src/config.h.in && rm src/config.h.in.bak
56
57./configure --host arm-apple-darwin
58
59cat << EOF >> src/config.h
60/* Add in so we have Apple Target Conditionals */
61#ifdef __APPLE__
62#include <TargetConditionals.h>
63#include <Availability.h>
64#endif
65
66/* Special configuration for ucontext */
67#undef HAVE_UCONTEXT_H
68#undef PC_FROM_UCONTEXT
69#if defined(__x86_64__)
70#define PC_FROM_UCONTEXT uc_mcontext->__ss.__rip
71#elif defined(__i386__)
72#define PC_FROM_UCONTEXT uc_mcontext->__ss.__eip
73#endif
74EOF
75
76# Prepare exported header include
77EXPORTED_INCLUDE_DIR="exported/glog"
78mkdir -p exported/glog
79cp -f src/glog/log_severity.h "$EXPORTED_INCLUDE_DIR/"
80cp -f src/glog/logging.h "$EXPORTED_INCLUDE_DIR/"
81cp -f src/glog/raw_logging.h "$EXPORTED_INCLUDE_DIR/"
82cp -f src/glog/stl_logging.h "$EXPORTED_INCLUDE_DIR/"
83cp -f src/glog/vlog_is_on.h "$EXPORTED_INCLUDE_DIR/"