From 6dfa11e2f70ba4f7fa8252adaeb6597f8ad3ffb0 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 18 Jan 2022 17:25:11 +0200 Subject: [PATCH] make: improve diagnostic messages when the prebuilt tcc executable does not work/is missing --- GNUmakefile | 13 +++++++++++-- Makefile | 1 + cmd/tools/detect_tcc.v | 15 +++++++++++++++ make.bat | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 cmd/tools/detect_tcc.v diff --git a/GNUmakefile b/GNUmakefile index 3f7c7d3717..9d5d87c19c 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -76,7 +76,7 @@ endif endif endif -.PHONY: all clean fresh_vc fresh_tcc +.PHONY: all clean fresh_vc fresh_tcc check_for_working_tcc ifdef prod VFLAGS+=-prod @@ -95,6 +95,7 @@ else ./v2.exe -o $(V) $(VFLAGS) cmd/v rm -rf v1.exe v2.exe endif + @$(V) run cmd/tools/detect_tcc.v @echo "V has been successfully built" @$(V) -version @@ -110,16 +111,21 @@ latest_vc: @echo "Using local vc" endif +check_for_working_tcc: + @$(TMPTCC)/tcc.exe --version > /dev/null 2> /dev/null || echo "The executable '$(TMPTCC)/tcc.exe' does not work." + fresh_vc: rm -rf $(VC) $(GITFASTCLONE) $(VCREPO) $(VC) ifndef local latest_tcc: $(TMPTCC)/.git/config - cd $(TMPTCC) && $(GITCLEANPULL) + @pushd . > /dev/null && cd $(TMPTCC) && $(GITCLEANPULL) && popd > /dev/null + @$(MAKE) --quiet check_for_working_tcc 2> /dev/null else latest_tcc: @echo "Using local tcc" + @$(MAKE) --quiet check_for_working_tcc 2> /dev/null endif fresh_tcc: @@ -128,12 +134,15 @@ ifndef local # Check wether a TCC branch exists for the user's system configuration. ifneq (,$(findstring thirdparty-$(TCCOS)-$(TCCARCH), $(shell git ls-remote --heads $(TCCREPO) | sed 's/^[a-z0-9]*\trefs.heads.//'))) $(GITFASTCLONE) --branch thirdparty-$(TCCOS)-$(TCCARCH) $(TCCREPO) $(TMPTCC) + @$(MAKE) --quiet check_for_working_tcc 2> /dev/null else @echo 'Pre-built TCC not available for thirdparty-$(TCCOS)-$(TCCARCH) at $(TCCREPO), will use the system compiler: $(CC)' $(GITFASTCLONE) --branch thirdparty-unknown-unknown $(TCCREPO) $(TMPTCC) + @$(MAKE) --quiet check_for_working_tcc 2> /dev/null endif else @echo "Using local tccbin" + @$(MAKE) --quiet check_for_working_tcc 2> /dev/null endif $(TMPTCC)/.git/config: diff --git a/Makefile b/Makefile index 77a455ce5b..e37b6c4b51 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,4 @@ all: ./v2 -o v $(VFLAGS) cmd/v rm -rf v1 v2 vc/ @echo "V has been successfully built" + ./v run ./cmd/tools/detect_tcc.v diff --git a/cmd/tools/detect_tcc.v b/cmd/tools/detect_tcc.v new file mode 100644 index 0000000000..1543dc7382 --- /dev/null +++ b/cmd/tools/detect_tcc.v @@ -0,0 +1,15 @@ +fn main() { + $if tinyc { + println('Your `tcc` is working. Good - it is much faster at compiling C source code.') + exit(0) + } + + println(' +NB: `tcc` was not used, so unless you install it yourself, your backend +C compiler will be `cc`, which is usually either `clang`, `gcc` or `msvc`. + +These C compilers, are several times slower at compiling C source code, +compared to `tcc`. They do produce more optimised executables, but that +is done at the cost of compilation speed. +') +} diff --git a/make.bat b/make.bat index ac64b35513..6b9a8e5726 100644 --- a/make.bat +++ b/make.bat @@ -240,6 +240,7 @@ echo ERROR: please follow the instructions in https://github.com/vlang/v/wiki/In exit /b 1 :success +.\v.exe run cmd\tools\detect_tcc.v echo ^> V built successfully! echo ^> To add V to your PATH, run `.\v.exe symlink`.