@VMODULE relative paths in #flag lines
parent
67a13fc916
commit
2ce6b190dd
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
struct Parser {
|
struct Parser {
|
||||||
file_path string // "/home/user/hello.v"
|
file_path string // "/home/user/hello.v"
|
||||||
|
file_path_dir string // "/home/user"
|
||||||
file_name string // "hello.v"
|
file_name string // "hello.v"
|
||||||
file_platform string // ".v", "_windows.v", "_nix.v", "_darwin.v", "_linux.v" ...
|
file_platform string // ".v", "_windows.v", "_nix.v", "_darwin.v", "_linux.v" ...
|
||||||
// When p.file_pcguard != '', it contains a
|
// When p.file_pcguard != '', it contains a
|
||||||
|
@ -180,6 +181,7 @@ fn (v mut V) new_parser_from_file(path string) Parser {
|
||||||
p = {
|
p = {
|
||||||
p |
|
p |
|
||||||
file_path:path,
|
file_path:path,
|
||||||
|
file_path_dir:filepath.dir( path ),
|
||||||
file_name:path.all_after(os.path_separator),
|
file_name:path.all_after(os.path_separator),
|
||||||
file_platform:path_platform,
|
file_platform:path_platform,
|
||||||
file_pcguard:path_pcguard,
|
file_pcguard:path_pcguard,
|
||||||
|
|
|
@ -243,6 +243,7 @@ fn (p mut Parser) chash() {
|
||||||
if p.first_pass() {
|
if p.first_pass() {
|
||||||
mut flag := hash[5..]
|
mut flag := hash[5..]
|
||||||
// expand `@VROOT` `@VMOD` to absolute path
|
// expand `@VROOT` `@VMOD` to absolute path
|
||||||
|
flag = flag.replace('@VMODULE', p.file_path_dir)
|
||||||
flag = flag.replace('@VROOT', p.vroot)
|
flag = flag.replace('@VROOT', p.vroot)
|
||||||
flag = flag.replace('@VPATH', p.pref.vpath)
|
flag = flag.replace('@VPATH', p.pref.vpath)
|
||||||
flag = flag.replace('@VLIB_PATH', p.pref.vlib_path)
|
flag = flag.replace('@VLIB_PATH', p.pref.vlib_path)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
main
|
||||||
|
mod1/c/implementation.o
|
||||||
|
main_test
|
|
@ -0,0 +1,8 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
import mod1
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
res := mod1.vadd(1,2)
|
||||||
|
println( res )
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import mod1
|
||||||
|
|
||||||
|
fn test_using_c_code_in_the_same_module_works(){
|
||||||
|
assert 1003 == mod1.vadd(1,2)
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef ADD_H
|
||||||
|
#define ADD_H
|
||||||
|
|
||||||
|
int cadd(int a, int b);
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,5 @@
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int cadd(int a, int b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
module mod1
|
||||||
|
|
||||||
|
#flag -I @VMODULE/c
|
||||||
|
#flag @VMODULE/c/implementation.o
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
fn C.cadd(int,int) int
|
||||||
|
|
||||||
|
pub fn vadd(a int, b int) int {
|
||||||
|
return 1000 + C.cadd(a,b)
|
||||||
|
}
|
Loading…
Reference in New Issue