v: fix remaining macOS SDK and Linux cross-build CI failures (#31103)

This commit is contained in:
Alexander Medvednikov authored and GitHub committed 2026-10-25 05:13:52 +03:00
1 parent eac320816c
commit b9dbf3bf65
3 files changed
+125 -12

No files matched your search

+75
View File
@@ -418,6 +418,81 @@ fn test_linux_cross_link_flags_unwrap_clang_driver_flags() {
]
}
fn test_linux_cross_compiles_native_sources_in_flag_plan() {
$if windows {
return
}
root := os.join_path(os.vtmp_dir(), 'v3_linux_cross_sources_${os.getpid()}')
os.rmdir_all(root) or {}
os.mkdir_all(root)!
defer {
os.rmdir_all(root) or {}
}
build_dir := os.join_path(root, 'build space')
os.mkdir_all(build_dir)!
for source in ['before.c', 'objc.m', 'main.c', 'upper.C', 'side car.mm', 'side.cpp', 'signal.c',
'forced.c', 'retained.o'] {
os.write_file(os.join_path(build_dir, source), '')!
}
compiler := write_windows_prod_test_tool(os.join_path(root, 'fake-cc'), r'
set -eu
source=""
output=""
language=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) output="$2"; shift 2 ;;
-x) language="$2"; shift 2 ;;
-I|-D|-include|-target) shift 2 ;;
-*) shift ;;
*) [ -z "$source" ] || exit 91; source="$1"; shift ;;
esac
done
[ -f "$source" ] && [ -n "$output" ] || exit 92
printf "%s|%s\n" "$source" "$language" >> compiled-sources.log
printf "%s|%s\n" "$source" "$language" > "$output"
')
write_windows_prod_test_tool(os.join_path(root, 'sysroot', 'ld.lld'), r'
set -eu
output=""
objects=0
retained=0
while [ "$#" -gt 0 ]; do
case "$1" in
-o) output="$2"; shift 2 ;;
-L|-l|-m|-dynamic-linker) shift 2 ;;
linux_cross_*.o)
[ -f "$1" ] || exit 93
IFS= read -r identity < "$1"
printf "%s\n" "$identity" >> linked-sources.log
objects=$((objects + 1))
shift ;;
retained.o) [ -f "$1" ] || exit 94; retained=1; shift ;;
*.c|*.C|*.cpp|*.m|*.mm|*.S) exit 95 ;;
*) shift ;;
esac
done
[ "$objects" -eq 7 ] && [ "$retained" -eq 1 ] && [ -n "$output" ] || exit 96
: > "$output"
')
// Language selectors span argument sections; option operands are never inputs.
plan := V3CCompilerFlagPlan{
before_inputs: ['-I', 'includes.c', '-D', '-x', '-include', 'forced.c', '-x', 'c', 'before.c',
'-xobjective-c']
after_inputs: ['-D', 'NOT_A_SOURCE.cpp', '-x', 'objective-c++', 'side car.mm', '-x', 'none',
'side.cpp', '-x', 'c', 'signal.c', '-x', 'none', '-L', 'lib.c', '-l', 'dep', 'retained.o']
}
result := compile_v3_macos_linux_cross(compiler, &plan, ['objc.m', '-x', 'none', 'main.c',
'upper.C'], os.join_path(root, 'sysroot'), root,
build_dir, 'program', false, false)
assert result.exit_code == 0, result.output
expected := ['before.c|c', 'objc.m|objective-c', 'main.c|', 'upper.C|', 'side car.mm|objective-c++',
'side.cpp|', 'signal.c|c']
assert os.read_file(os.join_path(build_dir, 'compiled-sources.log'))!.split_into_lines() == expected
assert os.read_file(os.join_path(build_dir, 'linked-sources.log'))!.split_into_lines() == expected
assert os.is_file(os.join_path(build_dir, 'program'))
}
fn test_v3_implicit_tcc_uses_platform_compiler_for_non_c_objects() {
implicit_tcc := os.join_path(os.temp_dir(), 'bin', 'tcc')
assert c_source_object_compiler('', implicit_tcc, true, 'linux') == implicit_tcc
+30 -9
View File
@@ -3117,22 +3117,44 @@ fn v3_linux_cross_source_input(input string) bool {
}
fn compile_v3_macos_linux_cross(c_compiler string, c_flag_plan &V3CCompilerFlagPlan, compiler_inputs []string, sysroot string, vroot string, build_dir string, output_name string, show_command bool, is_shared bool) os.Result {
mut compile_flags := c_object_compile_flags(c_flag_plan.before_inputs)
compile_flags << c_object_compile_flags(c_flag_plan.after_inputs)
compile_flags << c_object_compile_flags(compiler_inputs)
mut inputs := c_flag_plan.before_inputs.clone()
inputs << compiler_inputs
inputs << c_flag_plan.after_inputs
mut compile_flags := c_object_compile_flags(inputs)
if '-fPIC' !in compile_flags {
compile_flags << '-fPIC'
}
mut objects := []string{}
mut source_index := 0
for raw_input in compiler_inputs {
input := raw_input.trim(' \t\r\n"\'')
if !v3_linux_cross_source_input(input) {
mut language := ''
mut i := 0
for i < inputs.len {
input := inputs[i].trim(' \t\r\n"\'')
if input == '-x' {
language = if i + 1 < inputs.len { inputs[i + 1].trim_space() } else { '' }
i += 2
continue
}
joined_language := c_joined_source_language(input)
if joined_language.len > 0 {
language = joined_language
i++
continue
}
if c_flag_consumes_next_operand(input) {
i += 2
continue
}
i++
if input.starts_with('-') || !v3_linux_cross_source_input(input) {
continue
}
object_name := 'linux_cross_${source_index}.o'
source_index++
mut args := compile_flags.clone()
if language !in ['', 'none'] {
args << ['-x', language]
}
args << ['-c', '-o', object_name, input]
if show_command {
println(' > ${cmdexec.display(c_compiler, args)}')
@@ -3143,7 +3165,7 @@ fn compile_v3_macos_linux_cross(c_compiler string, c_flag_plan &V3CCompilerFlagP
}
objects << object_name
}
if objects.len == 0 && !compiler_inputs.any(c_flag_is_object_file(it.trim_space())) {
if objects.len == 0 && !c_link_input_indices(inputs).any(c_flag_is_object_file(inputs[it].trim_space())) {
return os.Result{
exit_code: 1
output: 'Linux cross compilation has no C source or object input'
@@ -3183,8 +3205,7 @@ fn compile_v3_macos_linux_cross(c_compiler string, c_flag_plan &V3CCompilerFlagP
}
linker_args << os.join_path(sysroot, 'crti.o')
linker_args << objects
linker_args << v3_linux_cross_link_flags(compiler_inputs)
linker_args << v3_linux_cross_link_flags(c_flag_plan.after_inputs)
linker_args << v3_linux_cross_link_flags(inputs)
linker_args << ['-lc', '-lcrypto', '-lssl', '-lpthread', os.join_path(sysroot, 'crtn.o'), '-lm',
'-ldl']
linker := os.join_path(sysroot, 'ld.lld')
+20 -3
View File
@@ -121,7 +121,7 @@ fn test_x86_64_sdk_symbols_are_only_written_for_macos_and_portable_c() {
}
// The table is checked against the installed SDK: its headers have to link every
// listed function to the listed symbol on x86_64.
// available function to the listed symbol on x86_64.
fn test_x86_64_sdk_symbol_table_matches_the_installed_sdk() {
$if !macos {
return
@@ -129,13 +129,30 @@ fn test_x86_64_sdk_symbol_table_matches_the_installed_sdk() {
dir := os.join_path(os.vtmp_dir(), 'darwin_x64_sdk_${os.getpid()}')
os.mkdir_all(dir)!
defer { os.rmdir_all(dir) or {} }
// Query the compiler's SDK, which may differ from the running macOS version.
version_source := os.join_path(dir, 'sdk_version.c')
os.write_file(version_source, '#include <AvailabilityMacros.h>\nV_DARWIN_SDK_MAX __MAC_OS_X_VERSION_MAX_ALLOWED\n')!
version := cmdexec.run('cc', ['-arch', 'x86_64', '-E', '-P', version_source])
assert version.exit_code == 0, version.output
assert version.output.contains('V_DARWIN_SDK_MAX '), version.output
sdk_version := version.output.all_after('V_DARWIN_SDK_MAX ').trim_space().int()
assert sdk_version > 0, version.output
mut sdk_symbols := map[string]string{}
for name, symbol in c_darwin_x64_sdk_symbols {
// These dirent APIs were added in the macOS 26.4 SDK. Older SDKs still
// validate every other entry instead of failing on undeclared names.
if sdk_version < 260400 && name in ['fdscandir', 'fdscandir_b', 'scandirat', 'scandirat_b'] {
continue
}
sdk_symbols[name] = symbol
}
mut code := ''
for header in ['dirent.h', 'fts.h', 'ftw.h', 'glob.h', 'stdlib.h', 'syslog.h', 'unistd.h',
'sys/mount.h', 'sys/select.h', 'sys/stat.h'] {
code += '#include <${header}>\n'
}
code += 'void* v_sdk_symbols[] = {\n'
for name, _ in c_darwin_x64_sdk_symbols {
for name, _ in sdk_symbols {
code += '\t(void*)&${name},\n'
}
code += '};\n'
@@ -145,7 +162,7 @@ fn test_x86_64_sdk_symbol_table_matches_the_installed_sdk() {
build := cmdexec.run('cc', ['-arch', 'x86_64', '-w', '-c', '-o', object, source])
assert build.exit_code == 0, build.output
symbols := undefined_symbols(object)
for name, symbol in c_darwin_x64_sdk_symbols {
for name, symbol in sdk_symbols {
assert symbol in symbols, '${name}: ${symbols}'
}
}