From 8398e2f448ac076a4fd1841003a1e29be04fa722 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 29 Jan 2021 19:40:39 +0200 Subject: [PATCH] ci: fix -usecache for programs using thirdparty C libs --- cmd/tools/vtest-all.v | 21 ++++++++++++++++++--- vlib/v/builder/cc.v | 8 +++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cmd/tools/vtest-all.v b/cmd/tools/vtest-all.v index 4955d903e2..072824afcb 100644 --- a/cmd/tools/vtest-all.v +++ b/cmd/tools/vtest-all.v @@ -5,10 +5,10 @@ import term import time const ( - vexe = os.getenv('VEXE') - vroot = os.dir(vexe) + vexe = os.getenv('VEXE') + vroot = os.dir(vexe) args_string = os.args[1..].join(' ') - vargs = args_string.all_before('test-all') + vargs = args_string.all_before('test-all') ) fn main() { @@ -49,6 +49,14 @@ mut: fn get_all_commands() []Command { mut res := []Command{} + res << Command{ + line: '$vexe examples/hello_world.v' + okmsg: 'V can compile hello world.' + } + res << Command{ + line: '$vexe -o vtmp cmd/v' + okmsg: 'V can compile itself.' + } res << Command{ line: '$vexe $vargs -progress test-cleancode' okmsg: 'All important .v files are invariant when processed with `v fmt`' @@ -78,6 +86,13 @@ fn get_all_commands() []Command { line: '$vexe install nedpals.args' okmsg: '`v install` works.' } + // NB: test that a program that depends on thirdparty libraries with its + // own #flags (tetris depends on gg, which uses sokol) can be compiled + // with -usecache: + res << Command{ + line: '$vexe -usecache examples/tetris/tetris.v' + okmsg: '`v -usecache` works.' + } $if macos { res << Command{ line: '$vexe -o v.c cmd/v && cc -Werror v.c && rm -rf v.c' diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 9e8aa05c0a..b9efcfdc5e 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -174,6 +174,7 @@ mut: // args []string // ordinary C options like `-O2` wargs []string // for `-Wxyz` *exclusively* + pre_args []string // options that should go before .o_args o_args []string // for `-o target` source_args []string // for `x.tmp.c` post_args []string // options that should go after .o_args @@ -321,8 +322,8 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { cflags := v.get_os_cflags() ccoptions.o_args << cflags.c_options_only_object_files() defines, others, libs := cflags.defines_others_libs() - ccoptions.args << defines - ccoptions.args << others + ccoptions.pre_args << defines + ccoptions.pre_args << others ccoptions.linker_flags << libs // TODO: why is this duplicated from above? if v.pref.use_cache && v.pref.build_mode != .build_module { @@ -382,6 +383,7 @@ fn (ccoptions CcompilerOptions) all_args() []string { all << ccoptions.env_cflags all << ccoptions.args all << ccoptions.o_args + all << ccoptions.pre_args all << ccoptions.source_args all << ccoptions.post_args all << ccoptions.linker_flags @@ -537,7 +539,7 @@ fn (mut v Builder) cc() { // mut libs := []string{} // builtin.o os.o http.o etc if v.pref.build_mode == .build_module { - v.ccoptions.args << '-c' + v.ccoptions.pre_args << '-c' } else if v.pref.use_cache { mut built_modules := []string{} builtin_obj_path := v.rebuild_cached_module(vexe, 'vlib/builtin')