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

builder: support v.mod/@VROOT, fix -cflags and -cache

This commit is contained in:
Delyan Angelov 2020-04-11 09:57:31 +03:00
parent 053de0b8e3
commit ba799b3f85
5 changed files with 39 additions and 10 deletions

View File

@ -132,6 +132,7 @@ fn parse_args(args []string) (&pref.Preferences, string) {
'-obfuscate' { res.obfuscate = true }
'-translated' { res.translated = true }
'-showcc' { res.show_cc = true }
'-cache' { res.is_cache = true }
'-keepc' { res.is_keep_c = true }
//'-x64' { res.translated = true }
'-os' {
@ -144,6 +145,10 @@ fn parse_args(args []string) (&pref.Preferences, string) {
res.os = tmp
i++
}
'-cflags' {
res.cflags = cmdline.option(args, '-cflags', '')
i++
}
'-cc' {
res.ccompiler = cmdline.option(args, '-cc', 'cc')
i++

View File

@ -7,6 +7,7 @@ import (
v.table
v.pref
v.util
v.vmod
v.checker
v.parser
v.gen
@ -109,7 +110,7 @@ pub fn (b mut Builder) parse_imports() {
if mod in done_imports {
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))
// break
// println('module_search_paths:')
@ -267,9 +268,16 @@ fn module_path(mod string) string {
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)
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)
if b.pref.is_verbose {
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 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) {

View File

@ -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 {
debug_options = '-g -O0 -no-pie'
}
@ -182,7 +188,7 @@ fn (v mut Builder) cc() {
optimization_options += ' -flto'
}
}
if v.pref.ccompiler.contains('gcc') || guessed_compiler == 'gcc' {
if is_cc_gcc {
if debug_mode {
debug_options = '-g3 -no-pie'
}
@ -302,8 +308,17 @@ fn (v mut Builder) cc() {
a << cflags.c_options_without_object_files()
a << libs
if v.pref.show_cc {
a << pref.default_module_path + '/cache/vlib/builtin.o'
if v.pref.is_cache {
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

View File

@ -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 << v.pref.lookup_path
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)
}
}

View File

@ -848,7 +848,7 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
*/
//
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.
// Builtin function bodies are defined in builtin.o
g.definitions.writeln(');')