Skip to content

Commit 63187ca

Browse files
committed
Use clang and ninja for iOS, include iOS in make and ninja builds, fix host compilation
1 parent ddc75b1 commit 63187ca

4 files changed

Lines changed: 99 additions & 55 deletions

File tree

common.gypi

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -697,17 +697,48 @@
697697
'GCC_ENABLE_PASCAL_STRINGS': 'NO', # No -mpascal-strings
698698
'GCC_STRICT_ALIASING': 'NO', # -fno-strict-aliasing
699699
'PREBINDING': 'NO', # No -Wl,-prebind
700-
'IPHONEOS_DEPLOYMENT_TARGET': '14.0', # -miphoneos-version-min=14.0
701700
'USE_HEADERMAP': 'NO',
702-
'WARNING_CFLAGS': [
703-
'-Wall',
704-
'-Wendif-labels',
705-
'-W',
706-
'-Wno-unused-parameter',
707-
'-Wno-enum-constexpr-conversion',
708-
],
709701
},
710702
'target_conditions': [
703+
['_toolset=="host"', {
704+
'xcode_settings': {
705+
'MACOSX_DEPLOYMENT_TARGET': '13.5', # Use macOS deployment target for host tools
706+
'WARNING_CFLAGS': [
707+
'-Wall',
708+
'-Wendif-labels',
709+
'-W',
710+
'-Wno-unused-parameter',
711+
],
712+
},
713+
}, {
714+
'xcode_settings': {
715+
'IPHONEOS_DEPLOYMENT_TARGET': '14.0', # -miphoneos-version-min=14.0
716+
'WARNING_CFLAGS': [
717+
'-Wall',
718+
'-Wendif-labels',
719+
'-W',
720+
'-Wno-unused-parameter',
721+
'-Wno-enum-constexpr-conversion',
722+
],
723+
},
724+
'conditions': [
725+
['iossim!="true" and target_arch in "arm64 arm armv7s"', {
726+
'xcode_settings': {
727+
'OTHER_CFLAGS': [
728+
'-fembed-bitcode'
729+
],
730+
'OTHER_CPLUSPLUSFLAGS': [
731+
'-fembed-bitcode'
732+
],
733+
}
734+
}],
735+
['target_arch=="x64" or target_arch=="ia32" or (target_arch=="arm64" and iossim=="true")', {
736+
'xcode_settings': { 'SDKROOT': 'iphonesimulator' },
737+
}, {
738+
'xcode_settings': { 'SDKROOT': 'iphoneos', 'ENABLE_BITCODE': 'YES' },
739+
}],
740+
],
741+
}],
711742
['_type!="static_library"', {
712743
'xcode_settings': {
713744
'OTHER_LDFLAGS': [
@@ -724,16 +755,6 @@
724755
['target_arch=="x64"', {
725756
'xcode_settings': {'ARCHS': ['x86_64']},
726757
}],
727-
['iossim!="true" and target_arch in "arm64 arm armv7s"', {
728-
'xcode_settings': {
729-
'OTHER_CFLAGS': [
730-
'-fembed-bitcode'
731-
],
732-
'OTHER_CPLUSPLUSFLAGS': [
733-
'-fembed-bitcode'
734-
],
735-
}
736-
}],
737758
[ 'target_arch=="arm64"', {
738759
'xcode_settings': {'ARCHS': ['arm64']},
739760
}],
@@ -750,11 +771,6 @@
750771
'CLANG_CXX_LIBRARY': 'libc++',
751772
},
752773
}],
753-
['target_arch=="x64" or target_arch=="ia32" or (target_arch=="arm64" and iossim=="true")', {
754-
'xcode_settings': { 'SDKROOT': 'iphonesimulator' },
755-
}, {
756-
'xcode_settings': { 'SDKROOT': 'iphoneos', 'ENABLE_BITCODE': 'YES' },
757-
}],
758774
],
759775
}],
760776
['OS=="freebsd"', {

tools/gyp/pylib/gyp/generator/ninja.py

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
# the start of a string, while $| is used for variables that can appear
4343
# anywhere in a string.
4444
"INTERMEDIATE_DIR": "$!INTERMEDIATE_DIR",
45-
"SHARED_INTERMEDIATE_DIR": "$!PRODUCT_DIR/gen",
45+
# nodejs-mobile patch: allow multiple rules to generate the same object (host and target)
46+
"SHARED_INTERMEDIATE_DIR": "$!PRODUCT_DIR/$|OBJ/gen",
4647
"PRODUCT_DIR": "$!PRODUCT_DIR",
4748
"CONFIGURATION_NAME": "$|CONFIGURATION_NAME",
4849
# Special variables that may be used by gyp 'rule' targets.
@@ -283,6 +284,13 @@ def ExpandSpecial(self, path, product_dir=None):
283284
CONFIGURATION_NAME = "$|CONFIGURATION_NAME"
284285
path = path.replace(CONFIGURATION_NAME, self.config_name)
285286

287+
# nodejs-mobile patch: allow multiple rules to generate the same object (host and target)
288+
obj = "obj"
289+
if self.toolset != "target":
290+
obj += "." + self.toolset
291+
292+
path = path.replace("$|OBJ", obj)
293+
286294
return path
287295

288296
def ExpandRuleVariables(self, path, root, dirname, source, ext, name):
@@ -301,7 +309,8 @@ def GypPathToNinja(self, path, env=None):
301309
302310
See the above discourse on path conversions."""
303311
if env:
304-
if self.flavor == "mac":
312+
# nodejs-mobile patch: add ios
313+
if self.flavor in ("mac", "ios"):
305314
path = gyp.xcode_emulation.ExpandEnvVars(path, env)
306315
elif self.flavor == "win":
307316
path = gyp.msvs_emulation.ExpandMacros(path, env)
@@ -393,7 +402,8 @@ def WriteSpec(self, spec, config_name, generator_flags):
393402

394403
self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
395404
self.xcode_settings = self.msvs_settings = None
396-
if self.flavor == "mac":
405+
# nodejs-mobile patch: add ios
406+
if self.flavor in ("mac", "ios"):
397407
self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
398408
mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
399409
if mac_toolchain_dir:
@@ -409,7 +419,8 @@ def WriteSpec(self, spec, config_name, generator_flags):
409419
self.ninja.variable("cxx_host", "$cl_" + arch)
410420
self.ninja.variable("asm", "$ml_" + arch)
411421

412-
if self.flavor == "mac":
422+
# nodejs-mobile patch: add ios
423+
if self.flavor in ("mac", "ios"):
413424
self.archs = self.xcode_settings.GetActiveArchs(config_name)
414425
if len(self.archs) > 1:
415426
self.arch_subninjas = {
@@ -476,7 +487,8 @@ def WriteSpec(self, spec, config_name, generator_flags):
476487
print('spec.get("sources"): ', str(spec.get("sources")))
477488
raise
478489
if sources:
479-
if self.flavor == "mac" and len(self.archs) > 1:
490+
# nodejs-mobile patch: add ios
491+
if self.flavor in ("mac", "ios") and len(self.archs) > 1:
480492
# Write subninja file containing compile and link commands scoped to
481493
# a single arch if a fat binary is being built.
482494
for arch in self.archs:
@@ -512,14 +524,16 @@ def WriteSpec(self, spec, config_name, generator_flags):
512524
# Some actions/rules output 'sources' that are already object files.
513525
obj_outputs = [f for f in sources if f.endswith(self.obj_ext)]
514526
if obj_outputs:
515-
if self.flavor != "mac" or len(self.archs) == 1:
527+
# nodejs-mobile patch: add ios
528+
if self.flavor not in ("mac", "ios") or len(self.archs) == 1:
516529
link_deps += [self.GypPathToNinja(o) for o in obj_outputs]
517530
else:
518531
print(
519532
"Warning: Actions/rules writing object files don't work with "
520533
"multiarch targets, dropping. (target %s)" % spec["target_name"]
521534
)
522-
elif self.flavor == "mac" and len(self.archs) > 1:
535+
# nodejs-mobile patch: add ios
536+
elif self.flavor in ("mac", "ios") and len(self.archs) > 1:
523537
link_deps = collections.defaultdict(list)
524538

525539
compile_deps = self.target.actions_stamp or actions_depends
@@ -1027,7 +1041,8 @@ def WriteSources(
10271041
self.ninja.variable("nm", "$nm_host")
10281042
self.ninja.variable("readelf", "$readelf_host")
10291043

1030-
if self.flavor != "mac" or len(self.archs) == 1:
1044+
# nodejs-mobile patch: add ios
1045+
if self.flavor not in ("mac", "ios") or len(self.archs) == 1:
10311046
return self.WriteSourcesForArch(
10321047
self.ninja,
10331048
config_name,
@@ -1066,7 +1081,8 @@ def WriteSourcesForArch(
10661081
"""Write build rules to compile all of |sources|."""
10671082

10681083
extra_defines = []
1069-
if self.flavor == "mac":
1084+
# nodejs-mobile patch: add ios
1085+
if self.flavor in ("mac", "ios"):
10701086
cflags = self.xcode_settings.GetCflags(config_name, arch=arch)
10711087
cflags_c = self.xcode_settings.GetCflagsC(config_name)
10721088
cflags_cc = self.xcode_settings.GetCflagsCC(config_name)
@@ -1174,7 +1190,8 @@ def WriteSourcesForArch(
11741190
)
11751191

11761192
pch_commands = precompiled_header.GetPchBuildCommands(arch)
1177-
if self.flavor == "mac":
1193+
# nodejs-mobile patch: add ios
1194+
if self.flavor in ("mac", "ios"):
11781195
# Most targets use no precompiled headers, so only write these if needed.
11791196
for ext, var in [
11801197
("c", "cflags_pch_c"),
@@ -1195,7 +1212,8 @@ def WriteSourcesForArch(
11951212
self.WriteVariableList(
11961213
ninja_file, "cflags_cc", map(self.ExpandSpecial, cflags_cc)
11971214
)
1198-
if self.flavor == "mac":
1215+
# nodejs-mobile patch: add ios
1216+
if self.flavor in ("mac", "ios"):
11991217
self.WriteVariableList(
12001218
ninja_file, "cflags_objc", map(self.ExpandSpecial, cflags_objc)
12011219
)
@@ -1226,9 +1244,11 @@ def WriteSourcesForArch(
12261244
# Add the _asm suffix as msvs is capable of handling .cc and
12271245
# .asm files of the same name without collision.
12281246
obj_ext = "_asm.obj"
1229-
elif self.flavor == "mac" and ext == "m":
1247+
# nodejs-mobile patch: add ios
1248+
elif self.flavor in ("mac", "ios") and ext == "m":
12301249
command = "objc"
1231-
elif self.flavor == "mac" and ext == "mm":
1250+
# nodejs-mobile patch: add ios
1251+
elif self.flavor in ("mac", "ios") and ext == "mm":
12321252
command = "objcxx"
12331253
self.target.uses_cpp = True
12341254
elif self.flavor == "win" and ext == "rc":
@@ -1304,7 +1324,8 @@ def WritePchTargets(self, ninja_file, pch_commands):
13041324

13051325
def WriteLink(self, spec, config_name, config, link_deps, compile_deps):
13061326
"""Write out a link step. Fills out target.binary. """
1307-
if self.flavor != "mac" or len(self.archs) == 1:
1327+
# nodejs-mobile patch: add ios
1328+
if self.flavor not in ("mac", "ios") or len(self.archs) == 1:
13081329
return self.WriteLinkForArch(
13091330
self.ninja, spec, config_name, config, link_deps, compile_deps
13101331
)
@@ -1420,7 +1441,8 @@ def WriteLinkForArch(
14201441
elif self.toolset == "host":
14211442
env_ldflags = os.environ.get("LDFLAGS_host", "").split()
14221443

1423-
if self.flavor == "mac":
1444+
# nodejs-mobile patch: add ios
1445+
if self.flavor in ("mac", "ios"):
14241446
ldflags = self.xcode_settings.GetLdflags(
14251447
config_name,
14261448
self.ExpandSpecial(generator_default_variables["PRODUCT_DIR"]),
@@ -1492,7 +1514,8 @@ def WriteLinkForArch(
14921514
libraries = gyp.common.uniquer(
14931515
map(self.ExpandSpecial, spec.get("libraries", []))
14941516
)
1495-
if self.flavor == "mac":
1517+
# nodejs-mobile patch: add ios
1518+
if self.flavor in ("mac", "ios"):
14961519
libraries = self.xcode_settings.AdjustLibraries(libraries, config_name)
14971520
elif self.flavor == "win":
14981521
libraries = self.msvs_settings.AdjustLibraries(libraries)
@@ -1850,7 +1873,7 @@ def ComputeOutput(self, spec, arch=None):
18501873

18511874
if (
18521875
arch is None
1853-
and self.flavor == "mac"
1876+
and self.flavor in ("mac", "ios") # nodejs-mobile patch: add ios
18541877
and type
18551878
in ("static_library", "executable", "shared_library", "loadable_module")
18561879
):
@@ -1865,7 +1888,7 @@ def ComputeOutput(self, spec, arch=None):
18651888
# Some products go into the output root, libraries go into shared library
18661889
# dir, and everything else goes into the normal place.
18671890
type_in_output_root = ["executable", "loadable_module"]
1868-
if self.flavor == "mac" and self.toolset == "target":
1891+
if self.flavor in ("mac", "ios") and self.toolset == "target":
18691892
type_in_output_root += ["shared_library", "static_library"]
18701893
elif self.flavor == "win" and self.toolset == "target":
18711894
type_in_output_root += ["shared_library"]
@@ -1911,7 +1934,8 @@ def WriteNewNinjaRule(
19111934
description = self.msvs_settings.ConvertVSMacros(
19121935
description, config=self.config_name
19131936
)
1914-
elif self.flavor == "mac":
1937+
# nodejs-mobile patch: add ios
1938+
elif self.flavor in ("mac", "ios"):
19151939
# |env| is an empty list on non-mac.
19161940
args = [gyp.xcode_emulation.ExpandEnvVars(arg, env) for arg in args]
19171941
description = gyp.xcode_emulation.ExpandEnvVars(description, env)
@@ -1982,8 +2006,9 @@ def CalculateVariables(default_variables, params):
19822006
global generator_additional_non_configuration_keys
19832007
global generator_additional_path_sections
19842008
flavor = gyp.common.GetFlavor(params)
1985-
if flavor == "mac":
1986-
default_variables.setdefault("OS", "mac")
2009+
# nodejs-mobile patch: add ios
2010+
if flavor in ("mac", "ios"):
2011+
default_variables.setdefault("OS", flavor)
19872012
default_variables.setdefault("SHARED_LIB_SUFFIX", ".dylib")
19882013
default_variables.setdefault(
19892014
"SHARED_LIB_DIR", generator_default_variables["PRODUCT_DIR"]
@@ -2345,7 +2370,8 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
23452370
master_ninja.variable("ld", CommandWithWrapper("LINK", wrappers, ld))
23462371
master_ninja.variable("ldxx", CommandWithWrapper("LINK", wrappers, ldxx))
23472372
master_ninja.variable("ar", GetEnvironFallback(["AR_target", "AR"], ar))
2348-
if flavor != "mac":
2373+
# nodejs-mobile patch: add ios
2374+
if flavor not in ("mac", "ios"):
23492375
# Mac does not use readelf/nm for .TOC generation, so avoiding polluting
23502376
# the master ninja with extra unused variables.
23512377
master_ninja.variable("nm", GetEnvironFallback(["NM_target", "NM"], nm))
@@ -2793,7 +2819,8 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
27932819
)
27942820

27952821
spec = target_dicts[qualified_target]
2796-
if flavor == "mac":
2822+
# nodejs-mobile patch: add ios
2823+
if flavor in ("mac", "ios"):
27972824
gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[build_file], spec)
27982825

27992826
# If build_file is a symlink, we must not follow it because there's a chance
@@ -2956,4 +2983,4 @@ def GenerateOutput(target_list, target_dicts, data, params):
29562983
for config_name in config_names:
29572984
GenerateOutputForConfig(
29582985
target_list, target_dicts, data, params, config_name
2959-
)
2986+
)

tools/ios_framework_prepare.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ build_for_arm64_device() {
6767
--with-intl=none \
6868
--cross-compiling \
6969
--enable-static \
70+
--use_clang \
71+
--ninja \
7072
--openssl-no-asm \
7173
--v8-options=--jitless \
7274
--without-node-code-cache \
7375
--without-node-snapshot
74-
make -j$(getconf _NPROCESSORS_ONLN)
76+
JOBS=$(getconf _NPROCESSORS_ONLN) make -j$(getconf _NPROCESSORS_ONLN)
7577

7678
# Move compilation outputs
7779
mkdir -p $TARGET_LIBRARY_PATH/arm64-device
@@ -90,12 +92,14 @@ build_for_arm64_simulator() {
9092
--with-intl=none \
9193
--cross-compiling \
9294
--enable-static \
95+
--use_clang \
96+
--ninja \
9397
--openssl-no-asm \
9498
--v8-options=--jitless \
9599
--without-node-code-cache \
96100
--without-node-snapshot \
97101
--ios-simulator
98-
make -j$(getconf _NPROCESSORS_ONLN)
102+
JOBS=$(getconf _NPROCESSORS_ONLN) make -j$(getconf _NPROCESSORS_ONLN)
99103

100104
# Move compilation outputs
101105
mkdir -p $TARGET_LIBRARY_PATH/arm64-simulator
@@ -114,11 +118,13 @@ build_for_x64_simulator() {
114118
--with-intl=none \
115119
--cross-compiling \
116120
--enable-static \
121+
--use_clang \
122+
--ninja \
117123
--openssl-no-asm \
118124
--v8-options=--jitless \
119125
--without-node-code-cache \
120126
--without-node-snapshot
121-
arch -x86_64 make -j$(getconf _NPROCESSORS_ONLN)
127+
arch -x86_64 JOBS=$(getconf _NPROCESSORS_ONLN) make -j$(getconf _NPROCESSORS_ONLN)
122128

123129
# Move compilation outputs
124130
mkdir -p $TARGET_LIBRARY_PATH/x64-simulator

tools/v8_gypfiles/toolchain.gypi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,6 @@
587587
['OS=="ios"', {
588588
'target_conditions': [
589589
['_toolset=="host" and host_os=="mac"', {
590-
'xcode_settings': {
591-
'SDKROOT': '',
592-
'IPHONEOS_DEPLOYMENT_TARGET': '',
593-
'MACOSX_DEPLOYMENT_TARGET': '11.0',
594-
},
595590
'conditions':[
596591
['target_arch=="arm64" and host_arch != "arm64"', {
597592
'xcode_settings': {

0 commit comments

Comments
 (0)