From 956a5c00c80e5ea67e810a7e1326c6630f23f403 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 23 May 2024 09:29:02 +0300 Subject: [PATCH] pref, builder: make `./v -gc none -os freebsd examples/hello_world.v` work on linux too --- vlib/v/builder/cc.v | 7 ++----- vlib/v/pref/default.v | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 799f430486..5e80a774e1 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -877,7 +877,7 @@ fn (mut b Builder) cc_freebsd_cross() { cc_args << '-c "${b.out_name_c}"' cc_args << libs b.dump_c_options(cc_args) - mut cc_name := 'cc' + mut cc_name := b.pref.vcross_compiler_name() mut out_name := b.pref.out_name $if windows { cc_name = 'clang.exe' @@ -901,10 +901,7 @@ fn (mut b Builder) cc_freebsd_cross() { // -ldl b.dump_c_options(linker_args) // mut ldlld := '${sysroot}/ld.lld' - mut ldlld := '/opt/homebrew/opt/llvm/bin/ld.lld' - $if windows { - ldlld = 'ld.lld.exe' - } + mut ldlld := b.pref.vcross_linker_name() linker_cmd := '${b.quote_compiler_name(ldlld)} ' + linker_args.join(' ') // s = s.replace('SYSROOT', sysroot) // TODO: $ inter bug // s = s.replace('-o hi', '-o ' + c.pref.out_name) diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index 650520ae9e..0d408e88f0 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -306,12 +306,29 @@ pub fn vexe_path() string { return real_vexe_path } +pub fn (p &Preferences) vcross_linker_name() string { + vlname := os.getenv('VCROSS_LINKER_NAME') + if vlname != '' { + return vlname + } + $if macos { + return '/opt/homebrew/opt/llvm/bin/ld.lld' + } + $if windows { + return 'ld.lld.exe' + } + return 'ld.lld' +} + pub fn (p &Preferences) vcross_compiler_name() string { vccname := os.getenv('VCROSS_COMPILER_NAME') if vccname != '' { return vccname } if p.os == .windows { + if p.os == .freebsd { + return 'clang' + } if p.m64 { return 'x86_64-w64-mingw32-gcc' }