v: add support for iOS crosscompilation (#5943)

pull/5949/head
pancake 2020-07-23 06:58:44 +02:00 committed by GitHub
parent 0f98445f7f
commit 36352085ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 8 deletions

View File

@ -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.

View File

@ -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

View File

@ -453,9 +453,22 @@ pub fn system(cmd string) int {
ret = C._wsystem(wcmd.to_wide()) ret = C._wsystem(wcmd.to_wide())
} }
} $else { } $else {
unsafe { /*
ret = C.system(charptr(cmd.str)) // 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 {
ret = C.system(charptr(cmd.str))
}
/*
} }
*/
} }
if ret == -1 { if ret == -1 {
print_c_errno() print_c_errno()

View File

@ -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'
} }

View File

@ -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__'
} }

View File

@ -28,7 +28,7 @@ fn (mut p Parser) resolve_vroot(flag string) string {
vmod_path := vmod_file_location.vmod_folder vmod_path := vmod_file_location.vmod_folder
if p.pref.is_fmt { if p.pref.is_fmt {
return flag return flag
} }
return flag.replace('@VROOT', os.real_path(vmod_path)) return flag.replace('@VROOT', os.real_path(vmod_path))
} }
@ -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
} }

View File

@ -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
} }

View File

@ -339,7 +339,7 @@ fn must_exist(path string) {
if !os.exists(path) { if !os.exists(path) {
eprintln('v expects that `$path` exists, but it does not') eprintln('v expects that `$path` exists, but it does not')
exit(1) exit(1)
} }
} }
pub fn backend_from_string(s string) ?Backend { pub fn backend_from_string(s string) ?Backend {