os: implement os.system for iOS and uncomment the `$if ios` blocks (#5947)
parent
921b5cddd0
commit
04ef2a2671
|
@ -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
|
||||
|
||||
|
|
20
vlib/os/os.v
20
vlib/os/os.v
|
@ -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()
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -121,11 +121,9 @@ pub fn get_host_os() OS {
|
|||
$if linux {
|
||||
return .linux
|
||||
}
|
||||
/*
|
||||
$if ios {
|
||||
return .ios
|
||||
}
|
||||
*/
|
||||
$if macos {
|
||||
return .mac
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue