From 4e7db5bab00cda225af9c89b6b183bf76f2b7f18 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 3 Mar 2022 10:43:50 +0200 Subject: [PATCH] v.builder: streamline get_os_cflags/0, use pref.os_from_string to centralise string -> v.pref.OS conversion --- vlib/v/builder/cflags.v | 18 ++++++++++-------- vlib/v/pref/os.v | 8 +++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/vlib/v/builder/cflags.v b/vlib/v/builder/cflags.v index 1486f692b0..8231ed17ce 100644 --- a/vlib/v/builder/cflags.v +++ b/vlib/v/builder/cflags.v @@ -1,6 +1,7 @@ module builder import os +import v.pref import v.cflag // get flags for current os @@ -14,17 +15,18 @@ fn (mut v Builder) get_os_cflags() []cflag.CFlag { if flag.value.ends_with('.o') { flag.cached = v.pref.cache_manager.postfix_with_key2cpath('.o', os.real_path(flag.value)) } - if flag.os == '' || (flag.os == 'linux' && v.pref.os == .linux) - || (flag.os == 'macos' && v.pref.os == .macos) - || (flag.os == 'darwin' && v.pref.os == .macos) - || (flag.os == 'freebsd' && v.pref.os == .freebsd) - || (flag.os == 'windows' && v.pref.os == .windows) - || (flag.os == 'mingw' && v.pref.os == .windows && v.pref.ccompiler != 'msvc') - || (flag.os == 'solaris' && v.pref.os == .solaris) { + if flag.os == '' || flag.os in ctimedefines { flags << flag + continue } - if flag.os in ctimedefines { + fos := pref.os_from_string(flag.os) or { pref.OS.all } + if fos != .all && fos == v.pref.os { flags << flag + continue + } + if v.pref.os == .windows && flag.os == 'mingw' && v.pref.ccompiler != 'msvc' { + flags << flag + continue } } return flags diff --git a/vlib/v/pref/os.v b/vlib/v/pref/os.v index 97ad947b7c..52b9dea712 100644 --- a/vlib/v/pref/os.v +++ b/vlib/v/pref/os.v @@ -35,6 +35,7 @@ pub fn os_from_string(os_str string) ?OS { 'windows' { return .windows } 'ios' { return .ios } 'macos' { return .macos } + 'darwin' { return .macos } 'freebsd' { return .freebsd } 'openbsd' { return .openbsd } 'netbsd' { return .netbsd } @@ -50,8 +51,10 @@ pub fn os_from_string(os_str string) ?OS { 'raw' { return .raw } 'nix' { return .linux } 'wasm32' { return .wasm32 } - 'wasm32-wasi' { return .wasm32_wasi } + 'wasm32-wasi' { return .wasm32_wasi } // TODO: remove these *or* the _ ones 'wasm32-emscripten' { return .wasm32_emscripten } + 'wasm32_wasi' { return .wasm32_wasi } + 'wasm32_emscripten' { return .wasm32_emscripten } '' { return ._auto } else { return error('bad OS $os_str') } } @@ -85,6 +88,9 @@ pub fn (o OS) str() string { } pub fn get_host_os() OS { + $if android { + return .android + } $if linux { return .linux }