builder: support v.mod/@VROOT, fix -cflags and -cache
parent
053de0b8e3
commit
ba799b3f85
|
@ -132,6 +132,7 @@ fn parse_args(args []string) (&pref.Preferences, string) {
|
||||||
'-obfuscate' { res.obfuscate = true }
|
'-obfuscate' { res.obfuscate = true }
|
||||||
'-translated' { res.translated = true }
|
'-translated' { res.translated = true }
|
||||||
'-showcc' { res.show_cc = true }
|
'-showcc' { res.show_cc = true }
|
||||||
|
'-cache' { res.is_cache = true }
|
||||||
'-keepc' { res.is_keep_c = true }
|
'-keepc' { res.is_keep_c = true }
|
||||||
//'-x64' { res.translated = true }
|
//'-x64' { res.translated = true }
|
||||||
'-os' {
|
'-os' {
|
||||||
|
@ -144,6 +145,10 @@ fn parse_args(args []string) (&pref.Preferences, string) {
|
||||||
res.os = tmp
|
res.os = tmp
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
'-cflags' {
|
||||||
|
res.cflags = cmdline.option(args, '-cflags', '')
|
||||||
|
i++
|
||||||
|
}
|
||||||
'-cc' {
|
'-cc' {
|
||||||
res.ccompiler = cmdline.option(args, '-cc', 'cc')
|
res.ccompiler = cmdline.option(args, '-cc', 'cc')
|
||||||
i++
|
i++
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
v.table
|
v.table
|
||||||
v.pref
|
v.pref
|
||||||
v.util
|
v.util
|
||||||
|
v.vmod
|
||||||
v.checker
|
v.checker
|
||||||
v.parser
|
v.parser
|
||||||
v.gen
|
v.gen
|
||||||
|
@ -109,7 +110,7 @@ pub fn (b mut Builder) parse_imports() {
|
||||||
if mod in done_imports {
|
if mod in done_imports {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
import_path := b.find_module_path(mod) or {
|
import_path := b.find_module_path(mod, ast_file.path) or {
|
||||||
// v.parsers[i].error_with_token_index('cannot import module "$mod" (not found)', v.parsers[i].import_table.get_import_tok_idx(mod))
|
// v.parsers[i].error_with_token_index('cannot import module "$mod" (not found)', v.parsers[i].import_table.get_import_tok_idx(mod))
|
||||||
// break
|
// break
|
||||||
// println('module_search_paths:')
|
// println('module_search_paths:')
|
||||||
|
@ -267,9 +268,16 @@ fn module_path(mod string) string {
|
||||||
return mod.replace('.', os.path_separator)
|
return mod.replace('.', os.path_separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (b Builder) find_module_path(mod string) ?string {
|
pub fn (b Builder) find_module_path(mod string, fpath string) ?string {
|
||||||
|
// support @VROOT/v.mod relative paths:
|
||||||
|
vmod_file_location := vmod.mod_file_cacher.get( fpath )
|
||||||
mod_path := module_path(mod)
|
mod_path := module_path(mod)
|
||||||
for search_path in b.module_search_paths {
|
mut module_lookup_paths := []string
|
||||||
|
if vmod_file_location.vmod_file.len != 0 && !(vmod_file_location.vmod_folder in b.module_search_paths) {
|
||||||
|
module_lookup_paths << vmod_file_location.vmod_folder
|
||||||
|
}
|
||||||
|
module_lookup_paths << b.module_search_paths
|
||||||
|
for search_path in module_lookup_paths {
|
||||||
try_path := os.join_path(search_path, mod_path)
|
try_path := os.join_path(search_path, mod_path)
|
||||||
if b.pref.is_verbose {
|
if b.pref.is_verbose {
|
||||||
println(' >> trying to find $mod in $try_path ..')
|
println(' >> trying to find $mod in $try_path ..')
|
||||||
|
@ -281,7 +289,8 @@ pub fn (b Builder) find_module_path(mod string) ?string {
|
||||||
return try_path
|
return try_path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return error('module "$mod" not found')
|
smodule_lookup_paths := module_lookup_paths.join(', ')
|
||||||
|
return error('module "$mod" not found in:\n$smodule_lookup_paths')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verror(s string) {
|
fn verror(s string) {
|
||||||
|
|
|
@ -169,7 +169,13 @@ fn (v mut Builder) cc() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.pref.ccompiler.contains('clang') || guessed_compiler == 'clang' {
|
//
|
||||||
|
is_cc_clang := v.pref.ccompiler.contains('clang') || guessed_compiler == 'clang'
|
||||||
|
is_cc_tcc := v.pref.ccompiler.contains('tcc') || guessed_compiler == 'tcc'
|
||||||
|
is_cc_gcc := v.pref.ccompiler.contains('gcc') || guessed_compiler == 'gcc'
|
||||||
|
is_cc_msvc := v.pref.ccompiler.contains('msvc') || guessed_compiler == 'msvc'
|
||||||
|
//
|
||||||
|
if is_cc_clang {
|
||||||
if debug_mode {
|
if debug_mode {
|
||||||
debug_options = '-g -O0 -no-pie'
|
debug_options = '-g -O0 -no-pie'
|
||||||
}
|
}
|
||||||
|
@ -182,7 +188,7 @@ fn (v mut Builder) cc() {
|
||||||
optimization_options += ' -flto'
|
optimization_options += ' -flto'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.pref.ccompiler.contains('gcc') || guessed_compiler == 'gcc' {
|
if is_cc_gcc {
|
||||||
if debug_mode {
|
if debug_mode {
|
||||||
debug_options = '-g3 -no-pie'
|
debug_options = '-g3 -no-pie'
|
||||||
}
|
}
|
||||||
|
@ -302,8 +308,17 @@ fn (v mut Builder) cc() {
|
||||||
a << cflags.c_options_without_object_files()
|
a << cflags.c_options_without_object_files()
|
||||||
a << libs
|
a << libs
|
||||||
|
|
||||||
if v.pref.show_cc {
|
if v.pref.is_cache {
|
||||||
a << pref.default_module_path + '/cache/vlib/builtin.o'
|
cached_files := ['builtin.o', 'math.o']
|
||||||
|
for cfile in cached_files {
|
||||||
|
ofile := os.join_path(pref.default_module_path, 'cache', 'vlib', cfile)
|
||||||
|
if os.exists(ofile) {
|
||||||
|
a << ofile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !is_cc_tcc {
|
||||||
|
a << '-Xlinker -z -Xlinker muldefs'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Without these libs compilation will fail on Linux
|
// Without these libs compilation will fail on Linux
|
||||||
|
|
|
@ -139,7 +139,7 @@ fn (v mut Builder) set_module_lookup_paths() {
|
||||||
v.module_search_paths << os.join_path(v.compiled_dir, 'modules')
|
v.module_search_paths << os.join_path(v.compiled_dir, 'modules')
|
||||||
v.module_search_paths << v.pref.lookup_path
|
v.module_search_paths << v.pref.lookup_path
|
||||||
if v.pref.is_verbose {
|
if v.pref.is_verbose {
|
||||||
v.log('v.module_lookup_paths') // : $v.module_lookup_paths')
|
v.log('v.module_search_paths:')
|
||||||
println(v.module_search_paths)
|
println(v.module_search_paths)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -848,7 +848,7 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
|
||||||
*/
|
*/
|
||||||
//
|
//
|
||||||
g.fn_args(it.args, it.is_variadic)
|
g.fn_args(it.args, it.is_variadic)
|
||||||
if it.no_body || (g.pref.show_cc && it.is_builtin) {
|
if it.no_body || (g.pref.is_cache && it.is_builtin) {
|
||||||
// Just a function header.
|
// Just a function header.
|
||||||
// Builtin function bodies are defined in builtin.o
|
// Builtin function bodies are defined in builtin.o
|
||||||
g.definitions.writeln(');')
|
g.definitions.writeln(');')
|
||||||
|
|
Loading…
Reference in New Issue