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
|
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):
|
systems also (although we do not test it as regularly as for the above):
|
||||||
`android`, `ios`,
|
`vinix`,
|
||||||
|
`ios`,
|
||||||
|
`android`, `termux`,
|
||||||
`freebsd`, `openbsd`, `netbsd`, `dragonfly`,
|
`freebsd`, `openbsd`, `netbsd`, `dragonfly`,
|
||||||
`solaris`, `serenity`, `haiku`, `vinix`,
|
`solaris`, `serenity`, `haiku`,
|
||||||
`wasm32`, `wasm32-wasi`, `wasm32-emscripten`
|
`wasm32`, `wasm32-wasi`, `wasm32-emscripten`
|
||||||
|
|
||||||
Note that V has the concept of platform files, i.e. files ending
|
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.
|
// user_os returns current user operating system name.
|
||||||
pub fn user_os() string {
|
pub fn user_os() string {
|
||||||
$if linux {
|
$if linux {
|
||||||
|
if getenv('TERMUX_VERSION') != '' {
|
||||||
|
return 'termux'
|
||||||
|
}
|
||||||
return 'linux'
|
return 'linux'
|
||||||
}
|
}
|
||||||
$if macos {
|
$if macos {
|
||||||
@ -340,6 +343,9 @@ pub fn user_os() string {
|
|||||||
$if android {
|
$if android {
|
||||||
return 'android'
|
return 'android'
|
||||||
}
|
}
|
||||||
|
// $if termux {
|
||||||
|
// return 'termux'
|
||||||
|
// }
|
||||||
$if solaris {
|
$if solaris {
|
||||||
return 'solaris'
|
return 'solaris'
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ const (
|
|||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
valid_comptime_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu',
|
valid_comptime_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu',
|
||||||
'qnx', 'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'solaris',
|
'qnx', 'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'termux',
|
||||||
'haiku', 'serenity', 'vinix']
|
'solaris', 'haiku', 'serenity', 'vinix']
|
||||||
valid_comptime_compression_types = ['none', 'zlib']
|
valid_comptime_compression_types = ['none', 'zlib']
|
||||||
valid_comptime_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
|
valid_comptime_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
|
||||||
valid_comptime_if_platforms = ['amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64', 'rv32']
|
valid_comptime_if_platforms = ['amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64', 'rv32']
|
||||||
|
@ -39,6 +39,7 @@ pub enum Platform {
|
|||||||
dragonfly
|
dragonfly
|
||||||
js // for interoperability in prefs.OS
|
js // for interoperability in prefs.OS
|
||||||
android
|
android
|
||||||
|
termux // like android, but note that termux is running on devices natively, not cross compiling from other platforms
|
||||||
solaris
|
solaris
|
||||||
serenity
|
serenity
|
||||||
vinix
|
vinix
|
||||||
@ -64,6 +65,7 @@ pub fn platform_from_string(platform_str string) ?Platform {
|
|||||||
'serenity' { return .serenity }
|
'serenity' { return .serenity }
|
||||||
'vinix' { return .vinix }
|
'vinix' { return .vinix }
|
||||||
'android' { return .android }
|
'android' { return .android }
|
||||||
|
'termux' { return .termux }
|
||||||
'haiku' { return .haiku }
|
'haiku' { return .haiku }
|
||||||
'nix' { return .linux }
|
'nix' { return .linux }
|
||||||
'' { return .auto }
|
'' { return .auto }
|
||||||
|
@ -636,6 +636,10 @@ fn (mut g Gen) comptime_if_to_ifdef(name string, is_comptime_optional bool) ?str
|
|||||||
'android' {
|
'android' {
|
||||||
return '__ANDROID__'
|
return '__ANDROID__'
|
||||||
}
|
}
|
||||||
|
'termux' {
|
||||||
|
// Note: termux is running on Android natively
|
||||||
|
return '__ANDROID__'
|
||||||
|
}
|
||||||
'solaris' {
|
'solaris' {
|
||||||
return '__sun'
|
return '__sun'
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
module pref
|
module pref
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
pub enum OS {
|
pub enum OS {
|
||||||
_auto // Reserved so .macos cannot be misunderstood as auto
|
_auto // Reserved so .macos cannot be misunderstood as auto
|
||||||
ios
|
ios
|
||||||
@ -17,6 +19,7 @@ pub enum OS {
|
|||||||
js_browser
|
js_browser
|
||||||
js_freestanding
|
js_freestanding
|
||||||
android
|
android
|
||||||
|
termux // like android, but compiling/running natively on the devices
|
||||||
solaris
|
solaris
|
||||||
serenity
|
serenity
|
||||||
vinix
|
vinix
|
||||||
@ -47,6 +50,7 @@ pub fn os_from_string(os_str string) ?OS {
|
|||||||
'serenity' { return .serenity }
|
'serenity' { return .serenity }
|
||||||
'vinix' { return .vinix }
|
'vinix' { return .vinix }
|
||||||
'android' { return .android }
|
'android' { return .android }
|
||||||
|
'termux' { return .termux }
|
||||||
'haiku' { return .haiku }
|
'haiku' { return .haiku }
|
||||||
'raw' { return .raw }
|
'raw' { return .raw }
|
||||||
'nix' { return .linux }
|
'nix' { return .linux }
|
||||||
@ -75,6 +79,7 @@ pub fn (o OS) str() string {
|
|||||||
.js_freestanding { return 'JavaScript' }
|
.js_freestanding { return 'JavaScript' }
|
||||||
.js_browser { return 'JavaScript(Browser)' }
|
.js_browser { return 'JavaScript(Browser)' }
|
||||||
.android { return 'Android' }
|
.android { return 'Android' }
|
||||||
|
.termux { return 'Termux' }
|
||||||
.solaris { return 'Solaris' }
|
.solaris { return 'Solaris' }
|
||||||
.serenity { return 'SerenityOS' }
|
.serenity { return 'SerenityOS' }
|
||||||
.vinix { return 'Vinix' }
|
.vinix { return 'Vinix' }
|
||||||
@ -88,10 +93,13 @@ pub fn (o OS) str() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_host_os() OS {
|
pub fn get_host_os() OS {
|
||||||
|
$if linux {
|
||||||
$if android {
|
$if android {
|
||||||
|
if os.getenv('TERMUX_VERSION') != '' {
|
||||||
|
return .termux
|
||||||
|
}
|
||||||
return .android
|
return .android
|
||||||
}
|
}
|
||||||
$if linux {
|
|
||||||
return .linux
|
return .linux
|
||||||
}
|
}
|
||||||
$if ios {
|
$if ios {
|
||||||
|
@ -121,6 +121,10 @@ fn fname_without_platform_postfix(file string) string {
|
|||||||
'_',
|
'_',
|
||||||
'android.c.v',
|
'android.c.v',
|
||||||
'_',
|
'_',
|
||||||
|
'termux.c.v',
|
||||||
|
'_',
|
||||||
|
'android_outside_termux.c.v',
|
||||||
|
'_',
|
||||||
'freebsd.c.v',
|
'freebsd.c.v',
|
||||||
'_',
|
'_',
|
||||||
'openbsd.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')) {
|
if prefs.os != .ios && (file.ends_with('_ios.c.v') || file.ends_with('_ios.v')) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
//
|
|
||||||
if prefs.os != .android && file.ends_with('_android.c.v') {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if prefs.os != .freebsd && file.ends_with('_freebsd.c.v') {
|
if prefs.os != .freebsd && file.ends_with('_freebsd.c.v') {
|
||||||
return false
|
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') {
|
if prefs.os != .vinix && file.ends_with('_vinix.c.v') {
|
||||||
return false
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user