@@ -571,7 +571,7 @@ def _AppendPlatformVersionMinFlags(self, lst):
571
571
lst , "IPHONEOS_DEPLOYMENT_TARGET" , "-miphoneos-version-min=%s"
572
572
)
573
573
574
- def GetCflags (self , configname , arch = None ):
574
+ def GetCflags (self , configname , gyp_to_build_path , arch = None ):
575
575
"""Returns flags that need to be added to .c, .cc, .m, and .mm
576
576
compilations."""
577
577
# This functions (and the similar ones below) do not offer complete
@@ -590,6 +590,15 @@ def GetCflags(self, configname, arch=None):
590
590
if self ._Test ("CLANG_WARN_CONSTANT_CONVERSION" , "YES" , default = "NO" ):
591
591
cflags .append ("-Wconstant-conversion" )
592
592
593
+ if self ._AreModulesEnabled ():
594
+ cflags .append ("-fmodules" )
595
+ module_cache_path = self ._Settings ().get (
596
+ "CLANG_MODULE_CACHE_PATH" , self ._GetDefaultClangModuleCachePath ())
597
+ if arch :
598
+ module_cache_path = os .path .join (module_cache_path , arch )
599
+ cflags .append ("-fmodules-cache-path=\' %s\' " % module_cache_path )
600
+ cflags .append ("-F." )
601
+
593
602
if self ._Test ("GCC_CHAR_IS_UNSIGNED_CHAR" , "YES" , default = "NO" ):
594
603
cflags .append ("-funsigned-char" )
595
604
@@ -691,11 +700,185 @@ def GetCflags(self, configname, arch=None):
691
700
config = self .spec ["configurations" ][self .configname ]
692
701
framework_dirs = config .get ("mac_framework_dirs" , [])
693
702
for directory in framework_dirs :
694
- cflags .append ("-F" + directory . replace ( "$(SDKROOT)" , framework_root ))
703
+ cflags .append ("-F" + gyp_to_build_path ( directory ))
695
704
696
705
self .configname = None
697
706
return cflags
698
707
708
+ def AreModulesEnabled (self , configname ):
709
+ self .configname = configname
710
+ res = self ._AreModulesEnabled ()
711
+ self .configname = None
712
+ return res
713
+
714
+ def _AreModulesEnabled (self ):
715
+ res = self ._Test ("CLANG_ENABLE_MODULES" , "YES" , default = "NO" )
716
+ return res
717
+
718
+ def IsModuleDefined (self , configname ):
719
+ self .configname = configname
720
+ res = self ._IsModuleDefined ()
721
+ self .configname = None
722
+ return res
723
+
724
+ def _IsModuleDefined (self ):
725
+ res = self ._Test ("DEFINES_MODULE" , "YES" , default = "NO" )
726
+ return res
727
+
728
+ def IsSwiftWMOEnabled (self , configname ):
729
+ self .configname = configname
730
+ res = self ._IsSwiftWMOEnabled ()
731
+ self .configname = None
732
+ return res
733
+
734
+ def _IsSwiftWMOEnabled (self ):
735
+ return self ._Test ("SWIFT_OPTIMIZATION_LEVEL" , "-Owholemodule" , default = "-O" )
736
+
737
+ def GetProductModuleName (self , configname ):
738
+ self .configname = configname
739
+ swift_module_name = self ._GetProductModuleName ()
740
+ self .configname = None
741
+ return swift_module_name
742
+
743
+ def _GetProductModuleName (self ):
744
+ default_module_name = self .spec ["target_name" ].replace ("-" , "_" )
745
+ return self ._Settings ().get (
746
+ "PRODUCT_MODULE_NAME" , default_module_name )
747
+
748
+ def GetSwiftHeaderPath (self , configname , gyp_path_to_build_path , arch = None ):
749
+ self .configname = configname
750
+ swift_header_path = self ._GetSwiftHeaderPath (gyp_path_to_build_path , arch )
751
+ self .configname = None
752
+ return swift_header_path
753
+
754
+ def _GetSwiftHeaderPath (self , gyp_path_to_build_path , arch ):
755
+ swift_header_name = self ._Settings ().get (
756
+ "SWIFT_OBJC_INTERFACE_HEADER_NAME" ,
757
+ self ._GetProductModuleName () + "-Swift.h" )
758
+ # SWIFT_OBJC_INTERFACE_HEADER_NAME must just a file name without path
759
+ assert not os .path .dirname (swift_header_name )
760
+ if arch :
761
+ swift_header_name = re .sub (r"\.h$" , "." + arch + ".h" , swift_header_name )
762
+ swift_header_path = os .path .join ("$!INTERMEDIATE_DIR" , swift_header_name )
763
+ swift_header_path = gyp_path_to_build_path (swift_header_path )
764
+ return swift_header_path
765
+
766
+ def _GetCommonLibsPath (self ):
767
+ developer_dir = subprocess .check_output (["xcode-select" , "-p" ]).strip ().decode (sys .stdout .encoding )
768
+ base_toolchain_path = os .path .join (
769
+ developer_dir , "Toolchains/XcodeDefault.xctoolchain" )
770
+ base_toolchain_path = os .path .normpath (base_toolchain_path )
771
+
772
+ libs_path = os .path .join (base_toolchain_path , "usr" , "lib" )
773
+ assert os .path .exists (libs_path )
774
+ return libs_path
775
+
776
+ def GetPlatform (self , configname ):
777
+ sdk_path_basename = os .path .basename (self ._SdkPath (configname ))
778
+ if sdk_path_basename .lower ().startswith ("iphonesimulator" ):
779
+ platform = "iphonesimulator"
780
+ elif sdk_path_basename .lower ().startswith ("iphoneos" ):
781
+ platform = "iphoneos"
782
+ elif sdk_path_basename .lower ().startswith ("macosx" ):
783
+ platform = "macosx"
784
+ else :
785
+ assert False , "Unexpected platform"
786
+
787
+ return platform
788
+
789
+ def _GetDefaultClangModuleCachePath (self ):
790
+ return os .path .join (os .path .expanduser ("~" ),
791
+ "Library/Developer/Xcode/DerivedData/ModuleCache" )
792
+
793
+ def _GetSwiftCommonFlags (self , gyp_path_to_build_path , arch ):
794
+ assert arch
795
+
796
+ swift_flags = []
797
+ swift_flags .append ("-enable-objc-interop" )
798
+
799
+ if self ._IsModuleDefined ():
800
+ swift_flags .append ("-import-underlying-module" )
801
+
802
+ self ._Appendf (swift_flags , "IPHONEOS_DEPLOYMENT_TARGET" ,
803
+ "-target " + arch + "-apple-ios%s" )
804
+ self ._Appendf (swift_flags , "MACOSX_DEPLOYMENT_TARGET" ,
805
+ "-target " + arch + "-apple-macosx%s" )
806
+
807
+ swift_flags .append ("-sdk " + self ._SdkPath ())
808
+
809
+ swift_flags .append ("-g" )
810
+
811
+ swift_flags .append ("-parse-as-library" )
812
+
813
+ self ._Appendf (swift_flags ,
814
+ "CLANG_MODULE_CACHE_PATH" ,
815
+ "-module-cache-path \" %s\" " ,
816
+ self ._GetDefaultClangModuleCachePath ())
817
+
818
+ swift_flags .append ("-module-name " + self ._GetProductModuleName ())
819
+
820
+ if self ._Settings ().get ("SWIFT_OBJC_BRIDGING_HEADER" ):
821
+ import_header = self ._Settings ().get ("SWIFT_OBJC_BRIDGING_HEADER" )
822
+ import_header = gyp_path_to_build_path (import_header )
823
+ swift_flags .append ("-import-objc-header \" " + import_header + "\" " )
824
+
825
+ config = self .spec ["configurations" ][self .configname ]
826
+ framework_dirs = config .get ("mac_framework_dirs" , [])
827
+ sdk_root = self ._SdkPath ()
828
+ for directory in framework_dirs :
829
+ swift_flags .append ("-F" + gyp_path_to_build_path (directory ))
830
+
831
+ swift_flags .append ("-F." )
832
+
833
+ swift_flags .append ("-I." )
834
+ for i in config .get ("include_dirs" , []):
835
+ swift_flags .append ("-I" + gyp_path_to_build_path (i ))
836
+
837
+ return swift_flags
838
+
839
+ def GetBundleFrameworksFolderPath (self ):
840
+ return os .path .join (self .GetBundleContentsFolderPath (), "Frameworks" )
841
+
842
+ def GetBundlePublicHeadersFolderPath (self ):
843
+ return os .path .join (self .GetBundleContentsFolderPath (), "Headers" )
844
+
845
+ def GetBundlePrivateHeadersFolderPath (self ):
846
+ return os .path .join (self .GetBundleContentsFolderPath (), "PrivateHeaders" )
847
+
848
+ def GetBundleModulesFolderPath (self ):
849
+ return os .path .join (self .GetBundleContentsFolderPath (), "Modules" )
850
+
851
+ def GetSwiftCompileFlags (self , configname , gyp_path_to_build_path , arch ):
852
+ self .configname = configname
853
+
854
+ swift_flags = self ._GetSwiftCommonFlags (gyp_path_to_build_path , arch )
855
+
856
+ if self ._IsSwiftWMOEnabled ():
857
+ swift_flags .append ("-O" )
858
+ else :
859
+ self ._Appendf (swift_flags , "SWIFT_OPTIMIZATION_LEVEL" , "%s" , "-O" )
860
+
861
+ self .configname = None
862
+ return swift_flags
863
+
864
+ def GetSwiftMergeFlags (self , configname , gyp_path_to_build_path , arch ):
865
+ self .configname = configname
866
+
867
+ swift_flags = self ._GetSwiftCommonFlags (gyp_path_to_build_path , arch )
868
+
869
+ self .configname = None
870
+ return swift_flags
871
+
872
+ def GetSwiftLdflags (self , arch_module_path ):
873
+ ldflags = []
874
+
875
+ # Feels bad but necessary for Nan and n-api.
876
+ ldflags .append ("-undefined dynamic_lookup" )
877
+
878
+ ldflags .append ("-Xlinker -add_ast_path -Xlinker " + arch_module_path )
879
+ ldflags .append ("-L/usr/lib/swift" )
880
+ return ldflags
881
+
699
882
def GetCflagsC (self , configname ):
700
883
"""Returns flags that need to be added to .c, and .m compilations."""
701
884
self .configname = configname
@@ -938,6 +1121,10 @@ def GetLdflags(self, configname, product_dir, gyp_to_build_path, arch=None):
938
1121
+ gyp_to_build_path (self ._Settings ()["ORDER_FILE" ])
939
1122
)
940
1123
1124
+ if "BUNDLE_LOADER" in self ._Settings ():
1125
+ bundle_loader_path = gyp_to_build_path (self ._Settings ()["BUNDLE_LOADER" ])
1126
+ ldflags .append ("-bundle_loader " + bundle_loader_path )
1127
+
941
1128
if arch is not None :
942
1129
archs = [arch ]
943
1130
else :
@@ -958,15 +1145,16 @@ def GetLdflags(self, configname, product_dir, gyp_to_build_path, arch=None):
958
1145
ldflags .append ("-install_name " + install_name .replace (" " , r"\ " ))
959
1146
960
1147
for rpath in self ._Settings ().get ("LD_RUNPATH_SEARCH_PATHS" , []):
961
- ldflags .append ("-Wl, -rpath, " + rpath )
1148
+ ldflags .append ("-Xlinker -rpath -Xlinker " + rpath )
962
1149
963
1150
sdk_root = self ._SdkPath ()
964
1151
if not sdk_root :
965
1152
sdk_root = ""
966
1153
config = self .spec ["configurations" ][self .configname ]
967
1154
framework_dirs = config .get ("mac_framework_dirs" , [])
968
1155
for directory in framework_dirs :
969
- ldflags .append ("-F" + directory .replace ("$(SDKROOT)" , sdk_root ))
1156
+ ldflags .append ("-F" + gyp_to_build_path (directory ))
1157
+ ldflags .append ("-F." )
970
1158
971
1159
if self ._IsXCTest ():
972
1160
platform_root = self ._XcodePlatformPath (configname )
@@ -1213,6 +1401,13 @@ def _GetIOSPostbuilds(self, configname, output_binary):
1213
1401
)
1214
1402
return postbuilds
1215
1403
1404
+ def GetCodeSignIdentityKey (self , configname ):
1405
+ if not self .isIOS :
1406
+ return None
1407
+
1408
+ settings = self .xcode_settings [configname ]
1409
+ return self ._GetIOSCodeSignIdentityKey (settings )
1410
+
1216
1411
def _GetIOSCodeSignIdentityKey (self , settings ):
1217
1412
identity = settings .get ("CODE_SIGN_IDENTITY" )
1218
1413
if not identity :
@@ -1701,6 +1896,8 @@ def GetMacInfoPlist(product_dir, xcode_settings, gyp_path_to_build_path):
1701
1896
1702
1897
return info_plist , dest_plist , defines , extra_env
1703
1898
1899
+ def IsSwiftSupported ():
1900
+ return True
1704
1901
1705
1902
def _GetXcodeEnv (
1706
1903
xcode_settings , built_products_dir , srcroot , configuration , additional_settings = None
0 commit comments