From 00aecf92e785b7b8d2fdf524f750f58c9139fb8d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 26 Feb 2023 01:26:33 +0200 Subject: [PATCH] tools: make `v self` compile with tcc on Apple M1, since it is faster, and tcc now can handle it (#17409) --- cmd/tools/vself.v | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cmd/tools/vself.v b/cmd/tools/vself.v index a4bfe97b10..4d14dbe14e 100644 --- a/cmd/tools/vself.v +++ b/cmd/tools/vself.v @@ -2,11 +2,15 @@ module main import os import os.cmdline -import v.pref import v.util.recompilation const is_debug = os.args.contains('-debug') +// support a renamed `v` executable too: +const vexe = os.getenv_opt('VEXE') or { @VEXE } + +const vroot = os.dir(vexe) + fn main() { // make testing `v up` easier, by providing a way to force `v self` to fail, // to test the fallback logic: @@ -14,16 +18,24 @@ fn main() { eprintln('v self failed') exit(1) } - // support a renamed `v` executable too: - vexe := pref.vexe_path() - vroot := os.dir(vexe) vexe_name := os.file_name(vexe) short_v_name := vexe_name.all_before('.') // recompilation.must_be_enabled(vroot, 'Please install V from source, to use `${vexe_name} self` .') os.chdir(vroot)! os.setenv('VCOLORS', 'always', true) - args := os.args[1..].filter(it != 'self') + mut args := os.args[1..].filter(it != 'self') + if args.len == 0 || ('-cc' !in args && '-prod' !in args) { + // compiling by default, i.e. `v self`: + uos := os.user_os() + uname := os.uname() + if uos == 'macos' && uname.machine == 'arm64' { + // Apple silicon, like m1, m2 etc + // Use tcc by default for V, since tinycc is much faster and also + // it already supports compiling many programs like V itself, that do not depend on inlined objective-C code + args << '-cc tcc' + } + } jargs := args.join(' ') obinary := cmdline.option(args, '-o', '') sargs := if obinary != '' { jargs } else { '${jargs} -o v2' }