From 9e2462a876571b5a42ff1b3630a32e5ba3090a3c Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 12 Jun 2025 13:26:02 +0300 Subject: [PATCH] native: fix again `v -os macos -experimental -b native -o hw.macos examples/hello_world.v`, after the latest changes to the backend --- .github/workflows/linux_ci.yml | 6 ++++++ ci/common/runner.v | 16 ++++++++++++++++ ci/linux_ci.vsh | 9 ++++++++- vlib/v/gen/native/expr.v | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux_ci.yml b/.github/workflows/linux_ci.yml index e809a7d835..99d64e1f95 100644 --- a/.github/workflows/linux_ci.yml +++ b/.github/workflows/linux_ci.yml @@ -75,6 +75,8 @@ jobs: run: v run ci/linux_ci.vsh test_leak_detector_tcc - name: Test leak detector not being active for normal compile run: v run ci/linux_ci.vsh test_leak_detector_not_active_tcc + - name: native cross compilation to macos + run: v run ci/linux_ci.vsh native_cross_compilation_to_macos gcc-linux: runs-on: ubuntu-24.04 @@ -121,6 +123,8 @@ jobs: run: v run ci/linux_ci.vsh build_modules_gcc - name: native machine code generation run: v run ci/linux_ci.vsh native_machine_code_generation_gcc + - name: native cross compilation to macos + run: v run ci/linux_ci.vsh native_cross_compilation_to_macos - name: compile vdoctor.v with -prod run: v run ci/linux_ci.vsh compile_vdoctor_prod_gcc - name: compile vup.v with -prod @@ -167,3 +171,5 @@ jobs: run: v run ci/linux_ci.vsh build_modules_clang - name: native machine code generation run: v run ci/linux_ci.vsh native_machine_code_generation_clang + - name: native cross compilation to macos + run: v run ci/linux_ci.vsh native_cross_compilation_to_macos diff --git a/ci/common/runner.v b/ci/common/runner.v index 09e7b58ff8..4787ce6e69 100644 --- a/ci/common/runner.v +++ b/ci/common/runner.v @@ -14,6 +14,22 @@ pub fn exec(command string) { } } +pub fn file_size_greater_than(fpath string, min_fsize u64) { + log.info('path should exist `${fpath}` ...') + if !os.exists(fpath) { + exit(1) + } + log.info('path exists, and should be a file: `${fpath}` ...') + if !os.is_file(fpath) { + exit(2) + } + real_size := os.file_size(fpath) + log.info('actual file size of `${fpath}` is ${real_size}, wanted: ${min_fsize}, diff: ${real_size - min_fsize}.') + if real_size < min_fsize { + exit(3) + } +} + const self_command = 'v ' + os.real_path(os.executable()).replace_once(os.real_path(@VROOT), '').trim_left('/\\') + '.vsh' diff --git a/ci/linux_ci.vsh b/ci/linux_ci.vsh index 99d4efea69..f4e3163fba 100644 --- a/ci/linux_ci.vsh +++ b/ci/linux_ci.vsh @@ -363,6 +363,12 @@ fn native_machine_code_generation_clang() { native_machine_code_generation_common() } +fn native_cross_compilation_to_macos() { + exec('v -os macos -experimental -b native -o hw.macos examples/hello_world.v') + common.file_size_greater_than('hw.macos', 8000) + exec('rm -f hw.macos') +} + // // Collect all tasks // @@ -409,7 +415,6 @@ const all_tasks = { 'build_option_test_autofree_gcc': Task{build_option_test_autofree_gcc, 'Build option_test.c.v with -autofree (gcc)'} 'v_self_compilation_parallel_cc_gcc': Task{v_self_compilation_parallel_cc_gcc, 'V self compilation with -parallel-cc (gcc)'} 'build_modules_gcc': Task{build_modules_gcc, 'Build modules (gcc)'} - 'native_machine_code_generation_gcc': Task{native_machine_code_generation_gcc, 'native machine code generation (gcc)'} 'compile_vdoctor_prod_gcc': Task{compile_vdoctor_prod_gcc, 'compile vdoctor with -prod (gcc)'} 'compile_vup_prod_gcc': Task{compile_vup_prod_gcc, 'compile vup with -prod (gcc)'} // clang tasks @@ -429,6 +434,8 @@ const all_tasks = { 'build_examples_autofree_clang': Task{build_examples_autofree_clang, 'Build examples with -autofree (clang)'} 'build_modules_clang': Task{build_modules_clang, 'Build modules (clang)'} 'native_machine_code_generation_clang': Task{native_machine_code_generation_clang, 'native machine code generation (clang)'} + 'native_machine_code_generation_gcc': Task{native_machine_code_generation_gcc, 'native machine code generation (gcc)'} + 'native_cross_compilation_to_macos': Task{native_cross_compilation_to_macos, 'native cross compilation to macos'} } common.run(all_tasks) diff --git a/vlib/v/gen/native/expr.v b/vlib/v/gen/native/expr.v index 1d6a36a89f..a06fc14ecd 100644 --- a/vlib/v/gen/native/expr.v +++ b/vlib/v/gen/native/expr.v @@ -196,6 +196,8 @@ fn (mut g Gen) extern_var_ident(var ExternVar) { g.extern_vars[g.pos()] = var.name g.code_gen.mov64(main_reg, Number(i64(0))) g.code_gen.mov_deref(main_reg, main_reg, ast.u64_type_idx) + } else if g.pref.os == .macos { + eprintln('## TODO, macos, extern_var_ident, var: ${var}') } else { g.n_error('${@LOCATION} unsupported os for ${var}') }