os: implement os.system for iOS and uncomment the `$if ios` blocks (#5947)

pull/5965/head
pancake 2020-07-24 09:17:32 +02:00 committed by GitHub
parent 921b5cddd0
commit 04ef2a2671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 12 deletions

View File

@ -68,6 +68,8 @@ fn C.fclose() int
fn C.pclose() int
fn C.system() int
fn C.posix_spawn(&int, charptr, voidptr, voidptr, &charptr, voidptr) int
fn C.waitpid(int, voidptr, int) int
fn C.setenv(charptr) int

View File

@ -453,22 +453,22 @@ pub fn system(cmd string) int {
ret = C._wsystem(wcmd.to_wide())
}
} $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
unsafe {
arg := [ c'/bin/sh', c'-c', byteptr(cmd.str), 0 ]
pid := 0
ret = C.posix_spawn(&pid, '/bin/sh', 0, 0, arg.data, 0)
status := 0
ret = C.waitpid(pid, &status, 0)
if C.WIFEXITED(status) {
ret = C.WEXITSTATUS(status)
}
}
} $else {
*/
unsafe {
ret = C.system(charptr(cmd.str))
}
/*
}
*/
}
if ret == -1 {
print_c_errno()

View File

@ -536,6 +536,12 @@ fn (mut v Builder) cc() {
}
}
}
if v.pref.os == .ios {
ret := os.system('ldid2 -S $v.pref.out_name')
if ret != 0 {
eprintln('failed to run ldid2, try: brew install ldid')
}
}
}
fn (mut b Builder) cc_linux_cross() {

View File

@ -255,6 +255,7 @@ pub fn (mut g Gen) init() {
}
if g.pref.os == .ios {
g.cheaders.writeln('#define __TARGET_IOS__ 1')
g.cheaders.writeln('#include <spawn.h>')
}
g.write_builtin_types()
g.write_typedef_types()

View File

@ -121,11 +121,9 @@ pub fn get_host_os() OS {
$if linux {
return .linux
}
/*
$if ios {
return .ios
}
*/
$if macos {
return .mac
}