From 84e019ace22de841bc541090ca119375daecba9e Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 15 Apr 2026 02:08:49 +0300 Subject: [PATCH] pref: fix macOS builtin option error (fixes #16243) --- vlib/v/ast/cflags_test.v | 3 +++ vlib/v/ast/comptime_valid_idents.v | 7 ++++--- vlib/v/pref/os.v | 3 +++ vlib/v/pref/pref_test.v | 10 ++++++++++ vlib/v/pref/should_compile.v | 2 +- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/vlib/v/ast/cflags_test.v b/vlib/v/ast/cflags_test.v index e0f8498f8..389ea5547 100644 --- a/vlib/v/ast/cflags_test.v +++ b/vlib/v/ast/cflags_test.v @@ -15,6 +15,7 @@ fn test_parse_valid_cflags() { make_flag('mingw', no_name, '-mwindows'), make_flag('solaris', '-L', '/opt/local/lib'), make_flag('darwin', '-framework', 'Cocoa'), + make_flag('mac', '-l', 'openal'), make_flag('windows', '-l', 'gdi32'), make_flag(no_os, '-l', 'mysqlclient'), make_flag(no_os, no_name, '-test'), @@ -31,6 +32,7 @@ fn test_parse_valid_cflags() { parse_valid_flag(mut t, '-lmysqlclient') parse_valid_flag(mut t, '-test') parse_valid_flag(mut t, 'darwin -framework Cocoa') + parse_valid_flag(mut t, 'mac -lopenal') parse_valid_flag(mut t, 'freebsd -I/usr/local/include/freetype2') parse_valid_flag(mut t, 'linux -lglfw') parse_valid_flag(mut t, 'mingw -mwindows') @@ -56,6 +58,7 @@ fn test_parse_invalid_cflags() { assert_parse_invalid_flag(mut t, 'darwin `sdl2-config --cflags --libs` -lSDL2') // OS/compiler name only is not allowed assert_parse_invalid_flag(mut t, 'darwin') + assert_parse_invalid_flag(mut t, 'mac') assert_parse_invalid_flag(mut t, 'freebsd') assert_parse_invalid_flag(mut t, 'linux') assert_parse_invalid_flag(mut t, 'mingw') diff --git a/vlib/v/ast/comptime_valid_idents.v b/vlib/v/ast/comptime_valid_idents.v index abb4a61e5..c13857c57 100644 --- a/vlib/v/ast/comptime_valid_idents.v +++ b/vlib/v/ast/comptime_valid_idents.v @@ -2,9 +2,9 @@ module ast import v.pref -pub const valid_comptime_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu', 'qnx', - 'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'termux', 'solaris', - 'haiku', 'serenity', 'vinix', 'plan9', 'wasm32_emscripten'] +pub const valid_comptime_if_os = ['windows', 'ios', 'macos', 'mac', 'mach', 'darwin', 'hpux', 'gnu', + 'qnx', 'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'termux', + 'solaris', 'haiku', 'serenity', 'vinix', 'plan9', 'wasm32_emscripten'] pub const valid_comptime_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus'] pub const valid_comptime_if_platforms = ['amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64', 'rv32', 's390x', 'ppc64le', 'loongarch64', 'sparc64', 'ppc64', 'ppc'] @@ -181,6 +181,7 @@ pub const system_ident_map = { 'windows': '_WIN32' 'ios': '__TARGET_IOS__' 'macos': '__APPLE__' + 'mac': '__APPLE__' 'mach': '__MACH__' 'darwin': '__DARWIN__' 'hpux': '__HPUX__' diff --git a/vlib/v/pref/os.v b/vlib/v/pref/os.v index 8fbe81c6b..f92560dfa 100644 --- a/vlib/v/pref/os.v +++ b/vlib/v/pref/os.v @@ -57,6 +57,9 @@ pub fn os_from_string(os_str string) !OS { 'macos' { return .macos } + 'mac' { + return .macos + } 'darwin' { return .macos } diff --git a/vlib/v/pref/pref_test.v b/vlib/v/pref/pref_test.v index c75b3acc0..1e6f1d7f1 100644 --- a/vlib/v/pref/pref_test.v +++ b/vlib/v/pref/pref_test.v @@ -52,6 +52,16 @@ fn test_cross_compile_keeps_explicit_cc() { assert second.ccompiler == custom_cc } +fn test_mac_is_alias_for_macos() { + os_kind := pref.os_from_string('mac') or { + assert false, err.msg() + return + } + assert os_kind == .macos + assert pref.OS.macos.is_target_of('mac') + assert !pref.OS.linux.is_target_of('mac') +} + fn test_disable_explicit_mutability_flag() { target := os.join_path(vroot, 'examples', 'hello_world.v') prefs, _ := pref.parse_args_and_show_errors([], ['-disable-explicit-mutability', target], false) diff --git a/vlib/v/pref/should_compile.v b/vlib/v/pref/should_compile.v index 82949dacf..372aa9da0 100644 --- a/vlib/v/pref/should_compile.v +++ b/vlib/v/pref/should_compile.v @@ -312,7 +312,7 @@ pub fn (this_os OS) is_target_of(target string) bool { if (this_os == .windows && target == 'nix') || (this_os != .windows && target == 'windows') || (this_os != .linux && target == 'linux') - || (this_os != .macos && target in ['darwin', 'macos']) + || (this_os != .macos && target in ['darwin', 'macos', 'mac']) || (this_os != .ios && target == 'ios') || (this_os != .freebsd && target == 'freebsd') || (this_os != .openbsd && target == 'openbsd') -- 2.39.5