iOS: add support for bdgwc/libgc
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 12 Dec 2017 16:42:48 +0000 (11:42 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 17 Jan 2018 20:30:12 +0000 (15:30 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/platform/ios.nit
src/platform/xcode_templates.nit

index da9cfda..460de30 100644 (file)
@@ -32,7 +32,7 @@ private class IOSPlatform
        super Platform
 
        redef fun supports_libunwind do return false
-       redef fun supports_libgc do return false
+       redef fun supports_libgc do return true
        redef fun toolchain(toolcontext, compiler) do return new IOSToolchain(toolcontext, compiler)
 end
 
@@ -53,6 +53,8 @@ private class IOSToolchain
 
        redef fun default_outname do return "{super}.app"
 
+       private var bdwgc_dir: nullable String = null
+
        # Compile C files in `ios_project_root/app_project.name`
        redef fun compile_dir
        do
@@ -66,6 +68,20 @@ private class IOSToolchain
                if ios_project_root.file_exists then ios_project_root.rmdir
                compile_dir.mkdir
 
+               # Download the libgc/bdwgc sources
+               var nit_dir = toolcontext.nit_dir or else "."
+               var share_dir = (nit_dir/"share").realpath
+               if not share_dir.file_exists then
+                       print "iOS project error: Nit share directory not found, please use the environment variable NIT_DIR"
+                       exit 1
+               end
+
+               var bdwgc_dir = "{share_dir}/android-bdwgc/bdwgc"
+               self.bdwgc_dir = bdwgc_dir
+               if not bdwgc_dir.file_exists then
+                       toolcontext.exec_and_check(["{share_dir}/android-bdwgc/setup.sh"], "iOS project error")
+               end
+
                super
        end
 
@@ -151,6 +167,20 @@ private class IOSToolchain
                        pbx.add_file new PbxFile(file.filename.basename)
                end
 
+               # GC
+               if compiler.target_platform.supports_libgc then
+                       var bdwgc_dir = bdwgc_dir
+                       assert bdwgc_dir != null
+
+                       pbx.cflags = "-I {bdwgc_dir}/include/ -I {bdwgc_dir}/libatomic_ops/src -fno-strict-aliasing " +
+                       "-DWITH_LIBGC -DNO_EXECUTE_PERMISSION -DALL_INTERIOR_POINTERS -DGC_NO_THREADS_DISCOVERY -DNO_DYLD_BIND_FULLY_IMAGE " +
+                       "-DGC_DISABLE_INCREMENTAL -DGC_THREADS -DUSE_MMAP -DUSE_MUNMAP -DGC_GCJ_SUPPORT -DJAVA_FINALIZATION "
+
+                       var gc_file = new PbxFile("{bdwgc_dir}/extra/gc.c")
+                       gc_file.cflags = "-Wno-tautological-pointer-compare"
+                       pbx.add_file gc_file
+               end
+
                # Basic storyboard, mainly to have the right screen size
                var launch_screen_storyboard = new LaunchScreenStoryboardTemplate
                launch_screen_storyboard.title = app_project.name
index 6e0231a..7b353d4 100644 (file)
@@ -149,6 +149,9 @@ class PbxprojectTemplate
        # Name of the project
        var name: String
 
+       # OTHER_CFLAGS
+       var cflags = "" is writable
+
        # All body/implementation source files to be compiled
        private var source_files = new Array[PbxFile]
 
@@ -428,6 +431,7 @@ class PbxprojectTemplate
                                ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
                                INFOPLIST_FILE = {{{name}}}/Info.plist;
                                LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+                               OTHER_CFLAGS = "{{{cflags.escape_to_c}}}";
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Debug;
@@ -438,6 +442,7 @@ class PbxprojectTemplate
                                ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
                                INFOPLIST_FILE = {{{name}}}/Info.plist;
                                LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+                               OTHER_CFLAGS = "{{{cflags.escape_to_c}}}";
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Release;