mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v: add support for iOS crosscompilation (#5943)
This commit is contained in:
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.
|
||||
By default, the target OS is the host system.
|
||||
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`,
|
||||
`dragonfly`, `solaris`, `android` and `haiku`.
|
||||
List of OS supported by V: `linux`, `windows`, `ios`, `mac`, `freebsd`, `openbsd`,
|
||||
`netbsd`, `dragonfly`, `solaris`, `android` and `haiku`.
|
||||
|
||||
-sanitize
|
||||
Pass flags related to sanitization to the C compiler.
|
||||
|
@ -67,10 +67,8 @@ fn C.fclose() int
|
||||
|
||||
fn C.pclose() int
|
||||
|
||||
|
||||
fn C.system() int
|
||||
|
||||
|
||||
fn C.setenv(charptr) int
|
||||
|
||||
|
||||
|
17
vlib/os/os.v
17
vlib/os/os.v
@ -453,9 +453,22 @@ pub fn system(cmd string) int {
|
||||
ret = C._wsystem(wcmd.to_wide())
|
||||
}
|
||||
} $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 {
|
||||
print_c_errno()
|
||||
|
@ -136,6 +136,9 @@ fn (mut v Builder) cc() {
|
||||
return
|
||||
}
|
||||
}
|
||||
if v.pref.os == .ios {
|
||||
ccompiler = 'xcrun --sdk iphoneos gcc -arch arm64'
|
||||
}
|
||||
// arguments for the C compiler
|
||||
// TODO : activate -Werror once no warnings remain
|
||||
// '-Werror',
|
||||
@ -339,6 +342,9 @@ fn (mut v Builder) cc() {
|
||||
if v.pref.os == .mac {
|
||||
a << '-mmacosx-version-min=10.7'
|
||||
}
|
||||
if v.pref.os == .ios {
|
||||
a << '-miphoneos-version-min=10.0'
|
||||
}
|
||||
if v.pref.os == .windows {
|
||||
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_TMP(const char*, ...);')
|
||||
}
|
||||
if g.pref.os == .ios {
|
||||
g.cheaders.writeln('#define __TARGET_IOS__ 1')
|
||||
}
|
||||
g.write_builtin_types()
|
||||
g.write_typedef_types()
|
||||
g.write_typeof_functions()
|
||||
@ -3901,6 +3904,9 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) string {
|
||||
'windows' {
|
||||
return '_WIN32'
|
||||
}
|
||||
'ios' {
|
||||
return '__TARGET_IOS__'
|
||||
}
|
||||
'mac' {
|
||||
return '__APPLE__'
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ fn (mut p Parser) resolve_vroot(flag string) string {
|
||||
vmod_path := vmod_file_location.vmod_folder
|
||||
if p.pref.is_fmt {
|
||||
return flag
|
||||
}
|
||||
}
|
||||
return flag.replace('@VROOT', os.real_path(vmod_path))
|
||||
}
|
||||
|
||||
@ -271,6 +271,9 @@ fn os_from_string(os string) pref.OS {
|
||||
'windows' {
|
||||
return .windows
|
||||
}
|
||||
'ios' {
|
||||
return .ios
|
||||
}
|
||||
'mac' {
|
||||
return .mac
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ module pref
|
||||
|
||||
pub enum OS {
|
||||
_auto // Reserved so .mac cannot be misunderstood as auto
|
||||
ios
|
||||
mac
|
||||
linux
|
||||
windows
|
||||
@ -27,6 +28,9 @@ pub fn os_from_string(os_str string) ?OS {
|
||||
'windows' {
|
||||
return .windows
|
||||
}
|
||||
'ios' {
|
||||
return .ios
|
||||
}
|
||||
'mac' {
|
||||
return .mac
|
||||
}
|
||||
@ -74,6 +78,9 @@ pub fn (o OS) str() string {
|
||||
._auto {
|
||||
return 'RESERVED: AUTO'
|
||||
}
|
||||
.ios {
|
||||
return 'iOS'
|
||||
}
|
||||
.mac {
|
||||
return 'MacOS'
|
||||
}
|
||||
@ -114,6 +121,11 @@ pub fn get_host_os() OS {
|
||||
$if linux {
|
||||
return .linux
|
||||
}
|
||||
/*
|
||||
$if ios {
|
||||
return .ios
|
||||
}
|
||||
*/
|
||||
$if macos {
|
||||
return .mac
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ fn must_exist(path string) {
|
||||
if !os.exists(path) {
|
||||
eprintln('v expects that `$path` exists, but it does not')
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn backend_from_string(s string) ?Backend {
|
||||
|
Loading…
Reference in New Issue
Block a user