v: add support for iOS crosscompilation (#5943)
							parent
							
								
									0f98445f7f
								
							
						
					
					
						commit
						36352085ae
					
				| 
						 | 
					@ -49,8 +49,8 @@ These build flags are enabled on `build` and `run` as long as the backend is set
 | 
				
			||||||
      Change the target OS that V tries to compile for.
 | 
					      Change the target OS that V tries to compile for.
 | 
				
			||||||
      By default, the target OS is the host system.
 | 
					      By default, the target OS is the host system.
 | 
				
			||||||
      When OS is `cross`, V will attempt to output cross-platform C code.
 | 
					      When OS is `cross`, V will attempt to output cross-platform C code.
 | 
				
			||||||
      List of OS supported by V: `linux`, `windows`, `mac`, `freebsd`, `openbsd`, `netbsd`,
 | 
					      List of OS supported by V: `linux`, `windows`, `ios`, `mac`, `freebsd`, `openbsd`,
 | 
				
			||||||
                                 `dragonfly`, `solaris`, `android` and `haiku`.
 | 
					                                 `netbsd`, `dragonfly`, `solaris`, `android` and `haiku`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   -sanitize
 | 
					   -sanitize
 | 
				
			||||||
      Pass flags related to sanitization to the C compiler.
 | 
					      Pass flags related to sanitization to the C compiler.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,10 +67,8 @@ fn C.fclose() int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn C.pclose() int
 | 
					fn C.pclose() int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
fn C.system() int
 | 
					fn C.system() int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
fn C.setenv(charptr) int
 | 
					fn C.setenv(charptr) int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								vlib/os/os.v
								
								
								
								
							
							
						
						
									
										13
									
								
								vlib/os/os.v
								
								
								
								
							| 
						 | 
					@ -453,9 +453,22 @@ pub fn system(cmd string) int {
 | 
				
			||||||
			ret = C._wsystem(wcmd.to_wide())
 | 
								ret = C._wsystem(wcmd.to_wide())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} $else {
 | 
						} $else {
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
							// make
 | 
				
			||||||
 | 
							// make selfcompile
 | 
				
			||||||
 | 
							// ./v -os ios hello.v
 | 
				
			||||||
 | 
							$if ios {
 | 
				
			||||||
 | 
								// TODO: use dlsym, use posix_spawn or embed ios_system
 | 
				
			||||||
 | 
								eprintln('system not supported on ios')
 | 
				
			||||||
 | 
								ret = 1
 | 
				
			||||||
 | 
							} $else {
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
			unsafe {
 | 
								unsafe {
 | 
				
			||||||
				ret = C.system(charptr(cmd.str))
 | 
									ret = C.system(charptr(cmd.str))
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if ret == -1 {
 | 
						if ret == -1 {
 | 
				
			||||||
		print_c_errno()
 | 
							print_c_errno()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -136,6 +136,9 @@ fn (mut v Builder) cc() {
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if v.pref.os == .ios {
 | 
				
			||||||
 | 
							ccompiler = 'xcrun --sdk iphoneos gcc -arch arm64'
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	// arguments for the C compiler
 | 
						// arguments for the C compiler
 | 
				
			||||||
	// TODO : activate -Werror once no warnings remain
 | 
						// TODO : activate -Werror once no warnings remain
 | 
				
			||||||
	// '-Werror',
 | 
						// '-Werror',
 | 
				
			||||||
| 
						 | 
					@ -339,6 +342,9 @@ fn (mut v Builder) cc() {
 | 
				
			||||||
	if v.pref.os == .mac {
 | 
						if v.pref.os == .mac {
 | 
				
			||||||
		a << '-mmacosx-version-min=10.7'
 | 
							a << '-mmacosx-version-min=10.7'
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if v.pref.os == .ios {
 | 
				
			||||||
 | 
							a << '-miphoneos-version-min=10.0'
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if v.pref.os == .windows {
 | 
						if v.pref.os == .windows {
 | 
				
			||||||
		a << '-municode'
 | 
							a << '-municode'
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -253,6 +253,9 @@ pub fn (mut g Gen) init() {
 | 
				
			||||||
		g.definitions.writeln('string _STR(const char*, int, ...);')
 | 
							g.definitions.writeln('string _STR(const char*, int, ...);')
 | 
				
			||||||
		g.definitions.writeln('string _STR_TMP(const char*, ...);')
 | 
							g.definitions.writeln('string _STR_TMP(const char*, ...);')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if g.pref.os == .ios {
 | 
				
			||||||
 | 
							g.cheaders.writeln('#define __TARGET_IOS__ 1')
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	g.write_builtin_types()
 | 
						g.write_builtin_types()
 | 
				
			||||||
	g.write_typedef_types()
 | 
						g.write_typedef_types()
 | 
				
			||||||
	g.write_typeof_functions()
 | 
						g.write_typeof_functions()
 | 
				
			||||||
| 
						 | 
					@ -3901,6 +3904,9 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) string {
 | 
				
			||||||
		'windows' {
 | 
							'windows' {
 | 
				
			||||||
			return '_WIN32'
 | 
								return '_WIN32'
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							'ios' {
 | 
				
			||||||
 | 
								return '__TARGET_IOS__'
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		'mac' {
 | 
							'mac' {
 | 
				
			||||||
			return '__APPLE__'
 | 
								return '__APPLE__'
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -271,6 +271,9 @@ fn os_from_string(os string) pref.OS {
 | 
				
			||||||
		'windows' {
 | 
							'windows' {
 | 
				
			||||||
			return .windows
 | 
								return .windows
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							'ios' {
 | 
				
			||||||
 | 
								return .ios
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		'mac' {
 | 
							'mac' {
 | 
				
			||||||
			return .mac
 | 
								return .mac
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@ module pref
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub enum OS {
 | 
					pub enum OS {
 | 
				
			||||||
	_auto // Reserved so .mac cannot be misunderstood as auto
 | 
						_auto // Reserved so .mac cannot be misunderstood as auto
 | 
				
			||||||
 | 
						ios
 | 
				
			||||||
	mac
 | 
						mac
 | 
				
			||||||
	linux
 | 
						linux
 | 
				
			||||||
	windows
 | 
						windows
 | 
				
			||||||
| 
						 | 
					@ -27,6 +28,9 @@ pub fn os_from_string(os_str string) ?OS {
 | 
				
			||||||
		'windows' {
 | 
							'windows' {
 | 
				
			||||||
			return .windows
 | 
								return .windows
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							'ios' {
 | 
				
			||||||
 | 
								return .ios
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		'mac' {
 | 
							'mac' {
 | 
				
			||||||
			return .mac
 | 
								return .mac
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -74,6 +78,9 @@ pub fn (o OS) str() string {
 | 
				
			||||||
		._auto {
 | 
							._auto {
 | 
				
			||||||
			return 'RESERVED: AUTO'
 | 
								return 'RESERVED: AUTO'
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							.ios {
 | 
				
			||||||
 | 
								return 'iOS'
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		.mac {
 | 
							.mac {
 | 
				
			||||||
			return 'MacOS'
 | 
								return 'MacOS'
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -114,6 +121,11 @@ pub fn get_host_os() OS {
 | 
				
			||||||
	$if linux {
 | 
						$if linux {
 | 
				
			||||||
		return .linux
 | 
							return .linux
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						$if ios {
 | 
				
			||||||
 | 
							return .ios
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
	$if macos {
 | 
						$if macos {
 | 
				
			||||||
		return .mac
 | 
							return .mac
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue