diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index a94cf1508d..acdc56268a 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -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 diff --git a/vlib/os/os.v b/vlib/os/os.v index b95f769d1c..2cb0139d6d 100644 --- a/vlib/os/os.v +++ b/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() diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 905092488e..d3dd18c87c 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -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() { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index bc3a846b08..f2ed4d1350 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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 ') } g.write_builtin_types() g.write_typedef_types() diff --git a/vlib/v/pref/os.v b/vlib/v/pref/os.v index 02b66e9174..632b004a6d 100644 --- a/vlib/v/pref/os.v +++ b/vlib/v/pref/os.v @@ -121,11 +121,9 @@ pub fn get_host_os() OS { $if linux { return .linux } -/* $if ios { return .ios } -*/ $if macos { return .mac }