mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v: support better separation of general Android vs Termux specific code (part 1)
This commit is contained in:
parent
ff0f75803d
commit
30401e003f
@ -108,9 +108,11 @@ see also `v help build`.
|
||||
|
||||
The compiler is known to also work, and has support for these operating
|
||||
systems also (although we do not test it as regularly as for the above):
|
||||
`android`, `ios`,
|
||||
`vinix`,
|
||||
`ios`,
|
||||
`android`, `termux`,
|
||||
`freebsd`, `openbsd`, `netbsd`, `dragonfly`,
|
||||
`solaris`, `serenity`, `haiku`, `vinix`,
|
||||
`solaris`, `serenity`, `haiku`,
|
||||
`wasm32`, `wasm32-wasi`, `wasm32-emscripten`
|
||||
|
||||
Note that V has the concept of platform files, i.e. files ending
|
||||
|
@ -317,6 +317,9 @@ pub fn get_raw_lines_joined() string {
|
||||
// user_os returns current user operating system name.
|
||||
pub fn user_os() string {
|
||||
$if linux {
|
||||
if getenv('TERMUX_VERSION') != '' {
|
||||
return 'termux'
|
||||
}
|
||||
return 'linux'
|
||||
}
|
||||
$if macos {
|
||||
@ -340,6 +343,9 @@ pub fn user_os() string {
|
||||
$if android {
|
||||
return 'android'
|
||||
}
|
||||
// $if termux {
|
||||
// return 'termux'
|
||||
// }
|
||||
$if solaris {
|
||||
return 'solaris'
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ const (
|
||||
|
||||
pub const (
|
||||
valid_comptime_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu',
|
||||
'qnx', 'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'solaris',
|
||||
'haiku', 'serenity', 'vinix']
|
||||
'qnx', 'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'termux',
|
||||
'solaris', 'haiku', 'serenity', 'vinix']
|
||||
valid_comptime_compression_types = ['none', 'zlib']
|
||||
valid_comptime_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
|
||||
valid_comptime_if_platforms = ['amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64', 'rv32']
|
||||
|
@ -39,6 +39,7 @@ pub enum Platform {
|
||||
dragonfly
|
||||
js // for interoperability in prefs.OS
|
||||
android
|
||||
termux // like android, but note that termux is running on devices natively, not cross compiling from other platforms
|
||||
solaris
|
||||
serenity
|
||||
vinix
|
||||
@ -64,6 +65,7 @@ pub fn platform_from_string(platform_str string) ?Platform {
|
||||
'serenity' { return .serenity }
|
||||
'vinix' { return .vinix }
|
||||
'android' { return .android }
|
||||
'termux' { return .termux }
|
||||
'haiku' { return .haiku }
|
||||
'nix' { return .linux }
|
||||
'' { return .auto }
|
||||
|
@ -636,6 +636,10 @@ fn (mut g Gen) comptime_if_to_ifdef(name string, is_comptime_optional bool) ?str
|
||||
'android' {
|
||||
return '__ANDROID__'
|
||||
}
|
||||
'termux' {
|
||||
// Note: termux is running on Android natively
|
||||
return '__ANDROID__'
|
||||
}
|
||||
'solaris' {
|
||||
return '__sun'
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
// that can be found in the LICENSE file.
|
||||
module pref
|
||||
|
||||
import os
|
||||
|
||||
pub enum OS {
|
||||
_auto // Reserved so .macos cannot be misunderstood as auto
|
||||
ios
|
||||
@ -17,6 +19,7 @@ pub enum OS {
|
||||
js_browser
|
||||
js_freestanding
|
||||
android
|
||||
termux // like android, but compiling/running natively on the devices
|
||||
solaris
|
||||
serenity
|
||||
vinix
|
||||
@ -47,6 +50,7 @@ pub fn os_from_string(os_str string) ?OS {
|
||||
'serenity' { return .serenity }
|
||||
'vinix' { return .vinix }
|
||||
'android' { return .android }
|
||||
'termux' { return .termux }
|
||||
'haiku' { return .haiku }
|
||||
'raw' { return .raw }
|
||||
'nix' { return .linux }
|
||||
@ -75,6 +79,7 @@ pub fn (o OS) str() string {
|
||||
.js_freestanding { return 'JavaScript' }
|
||||
.js_browser { return 'JavaScript(Browser)' }
|
||||
.android { return 'Android' }
|
||||
.termux { return 'Termux' }
|
||||
.solaris { return 'Solaris' }
|
||||
.serenity { return 'SerenityOS' }
|
||||
.vinix { return 'Vinix' }
|
||||
@ -88,10 +93,13 @@ pub fn (o OS) str() string {
|
||||
}
|
||||
|
||||
pub fn get_host_os() OS {
|
||||
$if android {
|
||||
return .android
|
||||
}
|
||||
$if linux {
|
||||
$if android {
|
||||
if os.getenv('TERMUX_VERSION') != '' {
|
||||
return .termux
|
||||
}
|
||||
return .android
|
||||
}
|
||||
return .linux
|
||||
}
|
||||
$if ios {
|
||||
|
@ -121,6 +121,10 @@ fn fname_without_platform_postfix(file string) string {
|
||||
'_',
|
||||
'android.c.v',
|
||||
'_',
|
||||
'termux.c.v',
|
||||
'_',
|
||||
'android_outside_termux.c.v',
|
||||
'_',
|
||||
'freebsd.c.v',
|
||||
'_',
|
||||
'openbsd.c.v',
|
||||
@ -178,10 +182,6 @@ pub fn (prefs &Preferences) should_compile_c(file string) bool {
|
||||
if prefs.os != .ios && (file.ends_with('_ios.c.v') || file.ends_with('_ios.v')) {
|
||||
return false
|
||||
}
|
||||
//
|
||||
if prefs.os != .android && file.ends_with('_android.c.v') {
|
||||
return false
|
||||
}
|
||||
if prefs.os != .freebsd && file.ends_with('_freebsd.c.v') {
|
||||
return false
|
||||
}
|
||||
@ -203,6 +203,30 @@ pub fn (prefs &Preferences) should_compile_c(file string) bool {
|
||||
if prefs.os != .vinix && file.ends_with('_vinix.c.v') {
|
||||
return false
|
||||
}
|
||||
if prefs.os in [.android, .termux] {
|
||||
// Note: Termux is running natively on Android devices, but the compilers there (clang) usually do not have access
|
||||
// to the Android SDK. The code here ensures that you can have `_termux.c.v` and `_android_outside_termux.c.v` postfixes,
|
||||
// to target both the cross compilation case (where the SDK headers are used and available), and the Termux case,
|
||||
// where the Android SDK is not used.
|
||||
if file.ends_with('_android.c.v') {
|
||||
// common case, should compile for both cross android and termux
|
||||
// eprintln('prefs.os: $prefs.os | file: $file | common')
|
||||
return true
|
||||
}
|
||||
if file.ends_with('_android_outside_termux.c.v') {
|
||||
// compile code that targets Android, but NOT Termux (i.e. the SDK is available)
|
||||
// eprintln('prefs.os: $prefs.os | file: $file | android_outside_termux')
|
||||
return prefs.os == .android
|
||||
}
|
||||
if file.ends_with('_termux.c.v') {
|
||||
// compile Termux specific code
|
||||
// eprintln('prefs.os: $prefs.os | file: $file | termux specific')
|
||||
return prefs.os == .termux
|
||||
}
|
||||
} else if file.ends_with('_android.c.v') || file.ends_with('_termux.c.v')
|
||||
|| file.ends_with('_android_outside_termux.c.v') {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user