Introduced properties

private var _app_project: IosProject

nitc :: IOSToolchain :: _app_project

app.nit project for the current compilation target
private var _bdwgc_dir: nullable String

nitc :: IOSToolchain :: _bdwgc_dir

private var _ios_project_root: String

nitc :: IOSToolchain :: _ios_project_root

Root of the iOS project, usually nit_compile/ios/
private fun app_project: IosProject

nitc :: IOSToolchain :: app_project

app.nit project for the current compilation target
private fun app_project=(app_project: IosProject)

nitc :: IOSToolchain :: app_project=

app.nit project for the current compilation target
private fun bdwgc_dir: nullable String

nitc :: IOSToolchain :: bdwgc_dir

private fun bdwgc_dir=(bdwgc_dir: nullable String)

nitc :: IOSToolchain :: bdwgc_dir=

init defaultinit(toolcontext: ToolContext, compiler: AbstractCompiler)

nitc :: IOSToolchain :: defaultinit

private fun ios_project_root: String

nitc :: IOSToolchain :: ios_project_root

Root of the iOS project, usually nit_compile/ios/
private fun ios_project_root=(ios_project_root: String)

nitc :: IOSToolchain :: ios_project_root=

Root of the iOS project, usually nit_compile/ios/

Redefined properties

redef type SELF: IOSToolchain

nitc $ IOSToolchain :: SELF

Type of this instance, automatically specialized in every class
redef fun compile_c_code(compile_dir: String)

nitc $ IOSToolchain :: compile_c_code

The C code is generated, compile it to an executable
redef fun compile_dir: String

nitc $ IOSToolchain :: compile_dir

Compile C files in ios_project_root/app_project.name
redef fun default_outname: String

nitc $ IOSToolchain :: default_outname

Get the default name of the executable to produce
redef fun write_files(compile_dir: String, cfiles: Array[String])

nitc $ IOSToolchain :: write_files

Write all source files to the compile_dir
redef fun write_makefile(compile_dir: String, cfiles: Array[String])

nitc $ IOSToolchain :: write_makefile

Write the Makefile

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _app_project: IosProject

nitc :: IOSToolchain :: _app_project

app.nit project for the current compilation target
private var _bdwgc_dir: nullable String

nitc :: IOSToolchain :: _bdwgc_dir

private var _compiler: AbstractCompiler

nitc :: Toolchain :: _compiler

Compiler of the target program
private var _ios_project_root: String

nitc :: IOSToolchain :: _ios_project_root

Root of the iOS project, usually nit_compile/ios/
private var _toolcontext: ToolContext

nitc :: Toolchain :: _toolcontext

Toolcontext
private fun app_project: IosProject

nitc :: IOSToolchain :: app_project

app.nit project for the current compilation target
private fun app_project=(app_project: IosProject)

nitc :: IOSToolchain :: app_project=

app.nit project for the current compilation target
private fun bdwgc_dir: nullable String

nitc :: IOSToolchain :: bdwgc_dir

private fun bdwgc_dir=(bdwgc_dir: nullable String)

nitc :: IOSToolchain :: bdwgc_dir=

protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun compile_c_code(compile_dir: String)

nitc :: MakefileToolchain :: compile_c_code

The C code is generated, compile it to an executable
fun compile_dir: String

nitc :: Toolchain :: compile_dir

Directory where to generate all C files
fun compiler: AbstractCompiler

nitc :: Toolchain :: compiler

Compiler of the target program
protected fun compiler=(compiler: AbstractCompiler)

nitc :: Toolchain :: compiler=

Compiler of the target program
fun default_outname: String

nitc :: MakefileToolchain :: default_outname

Get the default name of the executable to produce
init defaultinit(toolcontext: ToolContext, compiler: AbstractCompiler)

nitc :: IOSToolchain :: defaultinit

init defaultinit(toolcontext: ToolContext, compiler: AbstractCompiler)

nitc :: Toolchain :: defaultinit

fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
private fun ios_project_root: String

nitc :: IOSToolchain :: ios_project_root

Root of the iOS project, usually nit_compile/ios/
private fun ios_project_root=(ios_project_root: String)

nitc :: IOSToolchain :: ios_project_root=

Root of the iOS project, usually nit_compile/ios/
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun makefile_name: String

nitc :: MakefileToolchain :: makefile_name

Get the name of the Makefile to use
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun outfile(mainmodule: MModule): String

nitc :: MakefileToolchain :: outfile

Combine options and platform informations to get the final path of the outfile
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun root_compile_dir: String

nitc :: Toolchain :: root_compile_dir

Directory where to generate all files
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
protected fun toolcontext=(toolcontext: ToolContext)

nitc :: Toolchain :: toolcontext=

Toolcontext
abstract fun write_and_make

nitc :: Toolchain :: write_and_make

Write all C files and compile them
fun write_files(compile_dir: String, cfiles: Array[String])

nitc :: MakefileToolchain :: write_files

Write all source files to the compile_dir
fun write_makefile(compile_dir: String, cfiles: Array[String])

nitc :: MakefileToolchain :: write_makefile

Write the Makefile
package_diagram nitc::ios::IOSToolchain IOSToolchain nitc::MakefileToolchain MakefileToolchain nitc::ios::IOSToolchain->nitc::MakefileToolchain nitc::Toolchain Toolchain nitc::MakefileToolchain->nitc::Toolchain ...nitc::Toolchain ... ...nitc::Toolchain->nitc::Toolchain

Ancestors

interface Object

core :: Object

The root of the class hierarchy.
class Toolchain

nitc :: Toolchain

Build toolchain for a specific target program, varies per Platform

Parents

class MakefileToolchain

nitc :: MakefileToolchain

Default toolchain using a Makefile

Class definitions

nitc $ IOSToolchain
private class IOSToolchain
	super MakefileToolchain

	# Root of the iOS project, usually `nit_compile/ios/`
	var ios_project_root: String is noinit

	# `app.nit` project for the current compilation target
	var app_project = new IosProject(compiler.modelbuilder, compiler.mainmodule) is lazy

	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
		ios_project_root = root_compile_dir/"ios"
		return ios_project_root/app_project.short_name
	end

	redef fun write_files(compile_dir, cfiles)
	do
		# Clear the project directory before writing anything
		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

	redef fun write_makefile(compile_dir, cfiles)
	do
		var project_name = app_project.short_name

		# ---
		# project_folder (source code)

		# Create the plist in the same directory as the generated C code
		if not compile_dir.file_exists then compile_dir.mkdir
		var plist = new PlistTemplate(app_project.name, app_project.namespace,
			app_project.version, app_project.version_code.to_s)
		plist.write_to_file compile_dir/"Info.plist"

		# Copy the folder `ios/AppIcon.appiconset` from the root of the project
		var project_root = "."
		var mpackage = compiler.mainmodule.first_real_mmodule.mpackage
		if mpackage != null then
			var root = mpackage.root
			if root != null then
				var filepath = root.filepath
				if filepath != null then
					project_root = filepath
				end
			end
		end

		# Copy all resources
		var app_files = [project_root]
		app_files.add_all app_project.files

		var icons_found = false

		# Prepare the `Assets.xcassets` folder
		var target_assets_dir = compile_dir / "Assets.xcassets"
		if not target_assets_dir.file_exists then target_assets_dir.mkdir
		"""
{
  "info" : {
	"version" : 1,
	"author" : "nitc"
  }
}""".write_to_file target_assets_dir / "Contents.json"

		(compile_dir / "assets").mkdir

		for path in app_files do

			# Icon
			var icon_dir = path / "ios" / "AppIcon.appiconset"
			if icon_dir.file_exists then
				icons_found = true


				# copy the res folder to the compile dir
				icon_dir = icon_dir.realpath
				toolcontext.exec_and_check(["cp", "-R", icon_dir, target_assets_dir], "iOS project error")
			end

			# Assets
			var assets_dir = path / "assets"
			if assets_dir.file_exists then
				assets_dir = assets_dir.realpath
				toolcontext.exec_and_check(["cp", "-r", assets_dir, compile_dir], "iOS project error")
			end
		end

		# ---
		# project_folder.xcodeproj (projet meta data)

		# Create an XCode project directory
		var dir = ios_project_root/project_name+".xcodeproj"
		if not dir.file_exists then dir.mkdir

		# Create a PBX project file
		var pbx = new PbxprojectTemplate(project_name)

		## Register all source files
		for file in cfiles do pbx.add_file new PbxFile(file)
		for file in compiler.extern_bodies do
			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
		launch_screen_storyboard.subtitle = "app.nit"
		launch_screen_storyboard.write_to_file ios_project_root / "LaunchScreen.storyboard"

		# Register the Assets.xcassets folder in the project description
		if icons_found then
			var xcassets = new PbxFile("Assets.xcassets")
			pbx.add_file xcassets
		end

		pbx.write_to_file dir / "project.pbxproj"
	end

	redef fun compile_c_code(compile_dir)
	do
		var project_name = app_project.short_name
		var release = toolcontext.opt_release.value
		var outfile = outfile(compiler.mainmodule)

		# Compile with `xcodebuild`
		#
		# TODO support more than the iPhone and the simulator.
		var compile_mode = if release then "Release" else "Debug"
		var args = ["sh", "-c", "cd {ios_project_root}; " +
			"xcodebuild -quiet -target '{project_name}' " +
			"-destination 'platform=iOS Simulator,name=iPhone' " +
			"-configuration {compile_mode} " +
			 "ONLY_ACTIVE_ARCH=NO "+
			"-sdk iphonesimulator build"]
		toolcontext.exec_and_check(args, "iOS project error")

		# Move compiled app to destination
		if outfile.file_exists then
			var error = outfile.rmdir
			if error != null then
				print_error error
				exit 1
			end
		end

		args = ["mv", "{ios_project_root}/build/{compile_mode}-iphonesimulator/{project_name}.app", outfile]
		toolcontext.exec_and_check(args, "iOS project error")
	end
end
src/platform/ios.nit:45,1--229,3