v.builder: remove default link flags -lm, -ldl, -lpthread (use module specific link flags instead) (#10099)

pull/10106/head
Delyan Angelov 2021-05-14 14:28:53 +03:00 committed by GitHub
parent b728d89069
commit 20a22453cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 9 deletions

View File

@ -2,6 +2,10 @@ module dl
#include <dlfcn.h>
$if linux {
#flag -ldl
}
pub const (
rtld_now = C.RTLD_NOW
rtld_lazy = C.RTLD_LAZY

View File

@ -9,6 +9,15 @@ $if gcboehm ? {
}
#include "fontstash.h"
#flag -I /usr/local/Cellar/freetype/2.10.2/include/freetype2
$if windows {
$if tinyc {
#flag @VEXEROOT/thirdparty/tcc/lib/openlibm.o
}
} $else {
#flag -lm
}
//#flag -lfreetype
pub const (
// TODO: fontstash.used_import is used to keep v from warning about unused imports

View File

@ -4,11 +4,15 @@
module math
#include <math.h>
$if windows {
$if tinyc {
#flag @VEXEROOT/thirdparty/tcc/lib/openlibm.o
}
} $else {
#flag -lm
}
fn C.acos(x f64) f64
fn C.asin(x f64) f64

View File

@ -40,6 +40,8 @@ $if ios {
#flag solaris -DSOKOL_NO_ENTRY
// TODO end
#flag linux -ldl
$if gcboehm ? {
#define SOKOL_MALLOC GC_MALLOC
#define SOKOL_CALLOC(n,m) GC_MALLOC((n)*(m))

View File

@ -0,0 +1,13 @@
module threads
// This module adds the necessary compiler flags for using threads.
// It is automatically imported by code that does `go func()` .
// See vlib/v/parser/pratt.v, search for ast.GoExpr .
// The goal is that programs, that do not use threads at all will not need
// to link to -lpthread etc.
// NB: on some platforms like Android, linking -lpthread is not needed too.
// See https://stackoverflow.com/a/31277163/1904615
$if !windows && !android {
#flag -lpthread
}

View File

@ -0,0 +1,4 @@
module threads
// This file is just a placeholder.
// The actual implementation is backend/platform specific, so see threads.c.v, threads.js.v etc.

View File

@ -380,20 +380,11 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
// || os.user_os() == 'linux'
if !v.pref.is_bare && v.pref.build_mode != .build_module
&& v.pref.os in [.linux, .freebsd, .openbsd, .netbsd, .dragonfly, .solaris, .haiku] {
ccoptions.linker_flags << '-lm'
ccoptions.linker_flags << '-lpthread'
// -ldl is a Linux only thing. BSDs have it in libc.
if v.pref.os == .linux {
ccoptions.linker_flags << '-ldl'
}
if v.pref.os in [.freebsd, .netbsd] {
// Free/NetBSD: backtrace needs execinfo library while linking
ccoptions.linker_flags << '-lexecinfo'
}
}
if !v.pref.is_bare && v.pref.os == .js && os.user_os() == 'linux' {
ccoptions.linker_flags << '-lm'
}
ccoptions.env_cflags = os.getenv('CFLAGS')
ccoptions.env_ldflags = os.getenv('LDFLAGS')
$if trace_ccoptions ? {

View File

@ -519,6 +519,7 @@ fn (mut p Parser) go_expr() ast.GoExpr {
}
}
pos := spos.extend(p.prev_tok.position())
p.register_auto_import('sync.threads')
return ast.GoExpr{
call_expr: call_expr
pos: pos