1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: enable -gc boehm by default (#14577)

This commit is contained in:
spaceface 2022-06-08 23:44:29 +02:00 committed by GitHub
parent e6580fefaa
commit 4ed9780b80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 62 additions and 25 deletions

View File

@ -45,7 +45,7 @@ jobs:
- name: Compile to raw Android (non-graphic) compatible
run: |
# Test that V can compile non-graphic app to Android compatible code *without* using the -apk flag
./v -os android examples/toml.v
./v -os android -gc none examples/toml.v
linux-cross:
runs-on: ubuntu-20.04
@ -98,7 +98,7 @@ jobs:
- name: toml.v can be compiled to raw Android C
run: |
# Test that V can compile non-graphic app to Android compatible code *without* using the -apk flag
./v -os android examples/toml.v
./v -os android -gc none examples/toml.v
windows-cross:

View File

@ -228,7 +228,7 @@ jobs:
if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v'
timeout-minutes: 180
env:
VFLAGS: -cc clang
VFLAGS: -cc clang -gc none
VJOBS: 1
VTEST_SHOW_START: 1
steps:

View File

@ -17,7 +17,7 @@ jobs:
alpine-docker-musl-gcc:
runs-on: ubuntu-20.04
if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v'
timeout-minutes: 121
timeout-minutes: 181
container:
# Alpine docker pre-built container
image: thevlang/vlang:alpine-build
@ -58,7 +58,7 @@ jobs:
env:
V_CI_MUSL: 1
V_CI_UBUNTU_MUSL: 1
VFLAGS: -cc musl-gcc
VFLAGS: -cc musl-gcc -gc none
volumes:
- ${{github.workspace}}:/opt/vlang

View File

@ -14,6 +14,7 @@ jobs:
if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v'
timeout-minutes: 121
env:
VFLAGS: -gc none
VAB_FLAGS: --api 30 --build-tools 29.0.0 -v 3
steps:
- uses: actions/setup-java@v2

View File

@ -14,6 +14,8 @@ jobs:
vinix-build:
runs-on: ubuntu-20.04
if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v'
env:
VFLAGS: -gc none
steps:
- uses: actions/checkout@v2

View File

@ -28,6 +28,9 @@ endif
ifeq ($(_SYS),Linux)
LINUX := 1
TCCOS := linux
ifneq ($(shell ldd /bin/ls | grep musl),)
TCCOS := linuxmusl
endif
endif
ifeq ($(_SYS),Darwin)
@ -113,7 +116,7 @@ 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)

View File

@ -3,16 +3,16 @@ module builtin
$if dynamic_boehm ? {
$if windows {
$if tinyc {
#flag -I@VEXEROOT/thirdparty/libgc/include
#flag -L@VEXEROOT/thirdparty/tcc/lib
#flag -I @VEXEROOT/thirdparty/libgc/include
#flag -L @VEXEROOT/thirdparty/tcc/lib
#flag -lgc
} $else $if msvc {
#flag -DGC_BUILTIN_ATOMIC=1
#flag -I@VEXEROOT/thirdparty/libgc/include
#flag -I @VEXEROOT/thirdparty/libgc/include
} $else {
#flag -DGC_WIN32_THREADS=1
#flag -DGC_BUILTIN_ATOMIC=1
#flag -I@VEXEROOT/thirdparty/libgc
#flag -I @VEXEROOT/thirdparty/libgc
#flag @VEXEROOT/thirdparty/libgc/gc.o
}
} $else {
@ -31,7 +31,7 @@ $if dynamic_boehm ? {
#flag -DGC_BUILTIN_ATOMIC=1
$if macos || linux {
#flag -DGC_PTHREADS=1
#flag -I@VEXEROOT/thirdparty/libgc/include
#flag -I @VEXEROOT/thirdparty/libgc/include
$if (prod && !tinyc && !debug) || !(amd64 || arm64 || i386 || arm32) {
// TODO: replace the architecture check with a `!$exists("@VEXEROOT/thirdparty/tcc/lib/libgc.a")` comptime call
#flag @VEXEROOT/thirdparty/libgc/gc.o
@ -45,7 +45,7 @@ $if dynamic_boehm ? {
#flag -DBUS_PAGE_FAULT=T_PAGEFLT
#flag -DGC_PTHREADS=1
$if !tinyc {
#flag -I@VEXEROOT/thirdparty/libgc/include
#flag -I @VEXEROOT/thirdparty/libgc/include
#flag @VEXEROOT/thirdparty/libgc/gc.o
}
$if tinyc {
@ -62,11 +62,11 @@ $if dynamic_boehm ? {
#flag -DGC_NOT_DLL=1
#flag -DGC_WIN32_THREADS=1
$if tinyc {
#flag -I@VEXEROOT/thirdparty/libgc/include
#flag -I @VEXEROOT/thirdparty/libgc/include
#flag @VEXEROOT/thirdparty/tcc/lib/libgc.a
#flag -luser32
} $else {
#flag -I@VEXEROOT/thirdparty/libgc/include
#flag -I @VEXEROOT/thirdparty/libgc/include
#flag @VEXEROOT/thirdparty/libgc/gc.o
}
} $else $if $pkgconfig('bdw-gc') {

View File

@ -93,6 +93,13 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) {
}
return
}
if res.exit_code != 0 && v.pref.gc_mode != .no_gc && res.output.contains('libgc.a') {
$if windows {
verror(r'Your V installation may be out-of-date. Try removing `thirdparty\tcc\` and running `.\make.bat`')
} $else {
verror('Your V installation may be out-of-date. Try removing `thirdparty/tcc/` and running `make`')
}
}
for emsg_marker in [builder.c_verror_message_marker, 'error: include file '] {
if res.output.contains(emsg_marker) {
emessage := res.output.all_after(emsg_marker).all_before('\n').all_before('\r').trim_right('\r\n')

View File

@ -117,10 +117,14 @@ pub fn (cflags []CFlag) defines_others_libs() ([]string, []string, []string) {
mut others := []string{}
mut libs := []string{}
for copt in copts_without_obj_files {
if copt.starts_with('-l') || copt.ends_with('.a') {
if copt.starts_with('-l') {
libs << copt
continue
}
if copt.ends_with('.a') {
libs << '"$copt"'
continue
}
if copt.starts_with('-D') {
defines << copt
continue

View File

@ -85,6 +85,18 @@ pub fn (mut p Preferences) fill_with_defaults() {
}
rpath_name := os.file_name(rpath)
p.building_v = !p.is_repl && (rpath_name == 'v' || rpath_name == 'vfmt.v')
if p.gc_mode == .unknown {
if p.backend != .c || p.building_v || p.is_bare || p.ccompiler == 'msvc' {
p.gc_mode = .no_gc
p.build_options << ['-gc', 'none']
} else {
// enable the GC by default
p.gc_mode = .boehm_full_opt
p.parse_define('gcboehm')
p.parse_define('gcboehm_full')
p.parse_define('gcboehm_opt')
}
}
if p.os == ._auto {
// No OS specifed? Use current system
p.os = get_host_os()

View File

@ -24,6 +24,7 @@ pub enum AssertFailureMode {
}
pub enum GarbageCollectionMode {
unknown
no_gc
boehm_full // full garbage collection mode
boehm_incr // incremental garbage colletion mode
@ -204,7 +205,7 @@ pub mut:
cleanup_files []string // list of temporary *.tmp.c and *.tmp.c.rsp files. Cleaned up on successfull builds.
build_options []string // list of options, that should be passed down to `build-module`, if needed for -usecache
cache_manager vcache.CacheManager
gc_mode GarbageCollectionMode = .no_gc // .no_gc, .boehm, .boehm_leak, ...
gc_mode GarbageCollectionMode = .unknown // .no_gc, .boehm, .boehm_leak, ...
assert_failure_mode AssertFailureMode // whether to call abort() or print_backtrace() after an assertion failure
message_limit int = 100 // the maximum amount of warnings/errors/notices that will be accumulated
nofloat bool // for low level code, like kernels: replaces f32 with u32 and f64 with u64
@ -327,9 +328,15 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
'-gc' {
gc_mode := cmdline.option(current_args, '-gc', '')
match gc_mode {
'', 'none' {
'none' {
res.gc_mode = .no_gc
}
'', 'boehm' {
res.gc_mode = .boehm_full_opt // default mode
res.parse_define('gcboehm')
res.parse_define('gcboehm_full')
res.parse_define('gcboehm_opt')
}
'boehm_full' {
res.gc_mode = .boehm_full
res.parse_define('gcboehm')
@ -352,12 +359,6 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.parse_define('gcboehm_incr')
res.parse_define('gcboehm_opt')
}
'boehm' {
res.gc_mode = .boehm_full_opt // default mode
res.parse_define('gcboehm')
res.parse_define('gcboehm_full')
res.parse_define('gcboehm_opt')
}
'boehm_leak' {
res.gc_mode = .boehm_leak
res.parse_define('gcboehm')

View File

@ -86,7 +86,7 @@ fn test_all() {
base_filename := os.file_name(test).replace('.v', '')
exe_filename := '$wrkdir/$base_filename'
full_path_to_source_file := os.join_path(vroot, test)
compile_cmd := '${os.quoted_path(vexe)} -o ${os.quoted_path(exe_filename)} -cg -cflags "-w" -experimental -autofree ${os.quoted_path(full_path_to_source_file)}'
compile_cmd := '${os.quoted_path(vexe)} -o ${os.quoted_path(exe_filename)} -cg -cflags "-w" -experimental -gc none -autofree ${os.quoted_path(full_path_to_source_file)}'
vprintln('compile cmd: ${bold(compile_cmd)}')
res := os.execute(compile_cmd)
if res.exit_code != 0 {

View File

@ -55,7 +55,14 @@ pub fn new_cache_manager(opts []string) CacheManager {
os.write_file(readme_file, readme_content) or { panic(err) }
dlog(@FN, 'created readme_file:\n $readme_file')
}
original_vopts := opts.join('|')
mut deduped_opts := map[string]bool{}
for o in opts {
deduped_opts[o] = true
}
deduped_opts_keys := deduped_opts.keys().filter(it != '' && !it.starts_with("['gcboehm', "))
// TODO: do not filter the gcboehm options here, instead just start `v build-module vlib/builtin` without the -d gcboehm etc.
// Note: the current approach of filtering the gcboehm keys may interfere with (potential) other gc modes.
original_vopts := deduped_opts_keys.join('|')
return CacheManager{
basepath: vcache_basepath
vopts: original_vopts