Skip to content

Commit

Permalink
v: deprecate @VROOT in favour of @VMODROOT (#9795)
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Apr 19, 2021
1 parent 4b230d1 commit d4f3141
Show file tree
Hide file tree
Showing 41 changed files with 193 additions and 108 deletions.
18 changes: 11 additions & 7 deletions doc/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3555,20 +3555,20 @@ Module {
* Add these lines to the top of your module:
```v oksyntax
#flag -I @VROOT/c
#flag @VROOT/c/implementation.o
#flag -I @VMODROOT/c
#flag @VMODROOT/c/implementation.o
#include "header.h"
```
NB: @VROOT will be replaced by V with the *nearest parent folder, where there is a v.mod file*.
NB: @VMODROOT will be replaced by V with the *nearest parent folder, where there is a v.mod file*.
Any .v file beside or below the folder where the v.mod file is,
can use `#flag @VROOT/abc` to refer to this folder.
The @VROOT folder is also *prepended* to the module lookup path,
so you can *import* other modules under your @VROOT, by just naming them.
can use `#flag @VMODROOT/abc` to refer to this folder.
The @VMODROOT folder is also *prepended* to the module lookup path,
so you can *import* other modules under your @VMODROOT, by just naming them.
The instructions above will make V look for an compiled .o file in
your module `folder/c/implementation.o`.
If V finds it, the .o file will get linked to the main executable, that used the module.
If it does not find it, V assumes that there is a `@VROOT/c/implementation.c` file,
If it does not find it, V assumes that there is a `@VMODROOT/c/implementation.c` file,
and tries to compile it to a .o file, then will use that.
This allows you to have C code, that is contained in a V module, so that its distribution is easier.
Expand Down Expand Up @@ -3904,8 +3904,12 @@ that are substituted at compile time:
- `@LINE` => replaced with the V line number where it appears (as a string).
- `@COLUMN` => replaced with the column where it appears (as a string).
- `@VEXE` => replaced with the path to the V compiler
- `@VEXEROOT` => will be substituted with the *folder*,
where the V executable is (as a string).
- `@VHASH` => replaced with the shortened commit hash of the V compiler (as a string).
- `@VMOD_FILE` => replaced with the contents of the nearest v.mod file (as a string).
- `@VMODROOT` => will be substituted with the *folder*,
where the nearest v.mod file is (as a string).
That allows you to do the following example, useful while debugging/logging/tracing your code:
```v
Expand Down
2 changes: 1 addition & 1 deletion examples/sokol/02_cubes_glsl/cube_glsl.v
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import time
import gg.m4

// GLSL Include and functions
#flag -I @VROOT/.
#flag -I @VMODROOT/.
#include "cube_glsl.h" #Please use sokol-shdc to generate the necessary cube_glsl.h file from cube_glsl.glsl (see the instructions at the top of this file)

fn C.cube_shader_desc(gfx.Backend) &C.sg_shader_desc
Expand Down
2 changes: 1 addition & 1 deletion examples/sokol/03_march_tracing_glsl/rt_glsl.v
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import time

// GLSL Include and functions

#flag -I @VROOT/.
#flag -I @VMODROOT/.
#include "rt_glsl.h" #Please use sokol-shdc to generate the necessary rt_glsl.h file from rt_glsl.glsl (see the instructions at the top of this file)

fn C.rt_shader_desc(gfx.Backend) &C.sg_shader_desc
Expand Down
2 changes: 1 addition & 1 deletion examples/sokol/04_multi_shader_glsl/rt_glsl.v
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import sokol.sgl
import time

// GLSL Include and functions
#flag -I @VROOT/.
#flag -I @VMODROOT/.
#include "rt_glsl_march.h" #Please use sokol-shdc to generate the necessary rt_glsl_march.h file from rt_glsl_march.glsl (see the instructions at the top of this file)
#include "rt_glsl_puppy.h" #Please use sokol-shdc to generate the necessary rt_glsl_puppy.h file from rt_glsl_puppy.glsl (see the instructions at the top of this file)
fn C.rt_march_shader_desc(gfx.Backend) &C.sg_shader_desc
Expand Down
2 changes: 1 addition & 1 deletion examples/sokol/05_instancing_glsl/rt_glsl.v
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mut:
/******************************************************************************
* GLSL Include and functions
******************************************************************************/
#flag -I @VROOT/.
#flag -I @VMODROOT/.
#include "rt_glsl_instancing.h" #Please use sokol-shdc to generate the necessary rt_glsl_march.h file from rt_glsl_march.glsl (see the instructions at the top of this file)
fn C.instancing_shader_desc(gfx.Backend) &C.sg_shader_desc

Expand Down
2 changes: 1 addition & 1 deletion examples/sokol/06_obj_viewer/show_obj.v
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import obj

// GLSL Include and functions

#flag -I @VROOT/.
#flag -I @VMODROOT/.
#include "gouraud.h" #Please use sokol-shdc to generate the necessary rt_glsl.h file from rt_glsl.glsl (see the instructions at the top of this file)
fn C.gouraud_shader_desc(gfx.Backend) &C.sg_shader_desc

Expand Down
2 changes: 1 addition & 1 deletion vlib/builtin/builtin.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub fn print(s string) {
}

/*
#include "@VROOT/vlib/darwin/darwin.m"
#include "@VEXEROOT/vlib/darwin/darwin.m"
fn C.nsstring2(s string) voidptr
fn C.NSLog(x voidptr)
#include <asl.h>
Expand Down
4 changes: 2 additions & 2 deletions vlib/builtin/builtin_d_gcboehm.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ $if static_boehm ? {
#pkgconfig bdw-gc
}
$if windows {
#flag -I@VROOT/thirdparty/libgc/include
#flag -L@VROOT/thirdparty/libgc
#flag -I@VEXEROOT/thirdparty/libgc/include
#flag -L@VEXEROOT/thirdparty/libgc
}
#flag -lgc
}
Expand Down
2 changes: 1 addition & 1 deletion vlib/builtin/builtin_ios.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module builtin

// TODO: Remove this later, added to make sure v self works
$if ios {
#include "@VROOT/thirdparty/ios/ios.m"
#include "@VEXEROOT/thirdparty/ios/ios.m"
}
4 changes: 2 additions & 2 deletions vlib/clipboard/clipboard_darwin.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module clipboard
#include <libkern/OSAtomic.h>
#include <Cocoa/Cocoa.h>
#flag -framework Cocoa
#include "@VROOT/vlib/clipboard/clipboard_darwin.m"
#include "@VEXEROOT/vlib/clipboard/clipboard_darwin.m"

pub struct Clipboard {
pb voidptr
Expand All @@ -14,7 +14,7 @@ mut:

fn C.darwin_new_pasteboard() voidptr

fn C.darwin_get_pasteboard_text(voidptr) byteptr
fn C.darwin_get_pasteboard_text(voidptr) &byte

fn C.darwin_set_pasteboard_text(voidptr, string) bool

Expand Down
14 changes: 8 additions & 6 deletions vlib/darwin/darwin.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module darwin

struct C.NSString {}

#include "@VROOT/vlib/darwin/darwin.m"
#include "@VEXEROOT/vlib/darwin/darwin.m"

fn C.nsstring2(s string) voidptr

Expand All @@ -30,10 +30,10 @@ pub fn nsstring(s string) voidptr {
// for .app packages: .../my.app/Contents/Resources
// for cli: .../parent_folder/Resources

fn C.CFBundleCopyResourcesDirectoryURL(bundle voidptr) byteptr
fn C.CFBundleCopyResourcesDirectoryURL(bundle voidptr) &byte
fn C.CFBundleGetMainBundle() voidptr
fn C.CFURLGetFileSystemRepresentation(url byteptr, resolve_against_base bool, buffer byteptr, buffer_size int) int
fn C.CFRelease(url byteptr)
fn C.CFURLGetFileSystemRepresentation(url &byte, resolve_against_base bool, buffer &byte, buffer_size int) int
fn C.CFRelease(url &byte)

pub fn resource_path() string {
main_bundle := C.CFBundleGetMainBundle()
Expand All @@ -42,8 +42,10 @@ pub fn resource_path() string {
panic('CFBundleCopyResourcesDirectoryURL failed')
}
buffer_size := 4096
mut buffer := unsafe{ malloc(buffer_size) }
unsafe{ buffer[0] = 0 }
mut buffer := unsafe { malloc(buffer_size) }
unsafe {
buffer[0] = 0
}
conv_result := C.CFURLGetFileSystemRepresentation(resource_dir_url, true, buffer,
buffer_size)
if conv_result == 0 {
Expand Down
4 changes: 2 additions & 2 deletions vlib/fontstash/a_d_use_freetype.v
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module fontstash

#define FONS_USE_FREETYPE 1
#flag windows -I @VROOT/thirdparty/freetype/include
#flag windows -L @VROOT/thirdparty/freetype/win64
#flag windows -I @VEXEROOT/thirdparty/freetype/include
#flag windows -L @VEXEROOT/thirdparty/freetype/win64
#flag linux -I/usr/include/freetype2
#flag darwin -I/usr/local/include/freetype2
// brew on m1
Expand Down
2 changes: 1 addition & 1 deletion vlib/fontstash/fontstash.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module fontstash

#flag -I @VROOT/thirdparty/fontstash
#flag -I @VEXEROOT/thirdparty/fontstash
#define FONTSTASH_IMPLEMENTATION
$if gcboehm ? {
#define FONTSTASH_MALLOC GC_MALLOC
Expand Down
2 changes: 1 addition & 1 deletion vlib/gg/gg_darwin.c.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module gg

#include "@VROOT/vlib/gg/gg_darwin.m"
#include "@VEXEROOT/vlib/gg/gg_darwin.m"

fn C.gg_get_screen_size() Size

Expand Down
2 changes: 1 addition & 1 deletion vlib/hash/wyhash.c.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module hash

//#flag -I @VROOT/thirdparty/wyhash
//#flag -I @VEXEROOT/thirdparty/wyhash
//#include "wyhash.h"
fn C.wyhash(byteptr, u64, u64, &u64) u64
fn C.wyhash64(u64, u64) u64
Expand Down
4 changes: 2 additions & 2 deletions vlib/json/json_primitives.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// that can be found in the LICENSE file.
module json

#flag -I @VROOT/thirdparty/cJSON
#flag @VROOT/thirdparty/cJSON/cJSON.o
#flag -I @VEXEROOT/thirdparty/cJSON
#flag @VEXEROOT/thirdparty/cJSON/cJSON.o
#include "cJSON.h"
#define js_get(object, key) cJSON_GetObjectItemCaseSensitive((object), (key))

Expand Down
4 changes: 2 additions & 2 deletions vlib/math/big/big.v
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module big

// Wrapper for https://github.com/kokke/tiny-bignum-c
#flag -I @VROOT/thirdparty/bignum
#flag @VROOT/thirdparty/bignum/bn.o
#flag -I @VEXEROOT/thirdparty/bignum
#flag @VEXEROOT/thirdparty/bignum/bn.o
#include "bn.h"

struct C.bn {
Expand Down
2 changes: 1 addition & 1 deletion vlib/math/math.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module math
#include <math.h>
$if windows {
$if tinyc {
#flag @VROOT/thirdparty/tcc/lib/openlibm.o
#flag @VEXEROOT/thirdparty/tcc/lib/openlibm.o
}
}
fn C.acos(x f64) f64
Expand Down
4 changes: 2 additions & 2 deletions vlib/mysql/_cdefs_windows.c.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module mysql

#flag windows -I@VROOT/thirdparty/mysql/include
#flag windows @VROOT/thirdparty/mysql/lib/libmysql.dll
#flag windows -I@VEXEROOT/thirdparty/mysql/include
#flag windows @VEXEROOT/thirdparty/mysql/lib/libmysql.dll
#include <mysql.h> # Please install https://dev.mysql.com/downloads/installer/ , then put the include/ and lib/ folders in thirdparty/mysql
2 changes: 1 addition & 1 deletion vlib/net/http/backend_windows.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// that can be found in the LICENSE file.
module http

#flag windows -I @VROOT/thirdparty/vschannel
#flag windows -I @VEXEROOT/thirdparty/vschannel
#flag -l ws2_32 -l crypt32 -l secur32 -l user32
#include "vschannel.c"

Expand Down
4 changes: 2 additions & 2 deletions vlib/pg/pg.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import io
#flag -lpq
#flag linux -I/usr/include/postgresql
#flag darwin -I/opt/local/include/postgresql11
#flag windows -I @VROOT/thirdparty/pg/include
#flag windows -L @VROOT/thirdparty/pg/win64
#flag windows -I @VEXEROOT/thirdparty/pg/include
#flag windows -L @VEXEROOT/thirdparty/pg/win64

// PostgreSQL Source Code
// https://doxygen.postgresql.org/libpq-fe_8h.html
Expand Down
6 changes: 3 additions & 3 deletions vlib/picoev/picoev.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import picohttpparser
#include <netinet/tcp.h>
#include <fcntl.h>
#include <signal.h>
#flag -I @VROOT/thirdparty/picoev
#flag -L @VROOT/thirdparty/picoev
#flag @VROOT/thirdparty/picoev/picoev.o
#flag -I @VEXEROOT/thirdparty/picoev
#flag -L @VEXEROOT/thirdparty/picoev
#flag @VEXEROOT/thirdparty/picoev/picoev.o
#include "src/picoev.h"
const (
max_fds = 1024
Expand Down
6 changes: 3 additions & 3 deletions vlib/picohttpparser/picohttpparser.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// that can be found in the LICENSE file.
module picohttpparser

#flag -I @VROOT/thirdparty/picohttpparser
#flag -L @VROOT/thirdparty/picohttpparser
#flag @VROOT/thirdparty/picohttpparser/picohttpparser.o
#flag -I @VEXEROOT/thirdparty/picohttpparser
#flag -L @VEXEROOT/thirdparty/picohttpparser
#flag @VEXEROOT/thirdparty/picohttpparser/picohttpparser.o

#include "picohttpparser.h"

Expand Down
2 changes: 1 addition & 1 deletion vlib/sokol/audio/audio.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module audio

#flag -I @VROOT/thirdparty/sokol
#flag -I @VEXEROOT/thirdparty/sokol
#define SOKOL_IMPL
#include "sokol_audio.h"
#flag linux -lasound
Expand Down
4 changes: 2 additions & 2 deletions vlib/sokol/c/declaration.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub const (
used_import = 1
)

#flag -I @VROOT/thirdparty/sokol
#flag -I @VROOT/thirdparty/sokol/util
#flag -I @VEXEROOT/thirdparty/sokol
#flag -I @VEXEROOT/thirdparty/sokol/util
#flag freebsd -I /usr/local/include
#flag darwin -fobjc-arc
#flag linux -lX11 -lGL -lXcursor -lXi
Expand Down
10 changes: 5 additions & 5 deletions vlib/sqlite/sqlite.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module sqlite
#flag solaris -lsqlite3
#flag freebsd -I/usr/local/include
#flag freebsd -Wl -L/usr/local/lib -lsqlite3
#flag windows -I@VROOT/thirdparty/sqlite
#flag windows -L@VROOT/thirdparty/sqlite
#flag windows @VROOT/thirdparty/sqlite/sqlite3.o
// #flag linux -I @VROOT/thirdparty/sqlite
// #flag @VROOT/thirdparty/sqlite/sqlite.c
#flag windows -I@VEXEROOT/thirdparty/sqlite
#flag windows -L@VEXEROOT/thirdparty/sqlite
#flag windows @VEXEROOT/thirdparty/sqlite/sqlite3.o
// #flag linux -I @VEXEROOT/thirdparty/sqlite
// #flag @VEXEROOT/thirdparty/sqlite/sqlite.c
#include "sqlite3.h"
//
struct C.sqlite3 {
Expand Down
4 changes: 2 additions & 2 deletions vlib/stbi/stbi.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

module stbi

#flag -I @VROOT/thirdparty/stb_image
#flag -I @VEXEROOT/thirdparty/stb_image
#include "stb_image.h"
#flag @VROOT/thirdparty/stb_image/stbi.o
#flag @VEXEROOT/thirdparty/stb_image/stbi.o

pub struct Image {
pub mut:
Expand Down
12 changes: 6 additions & 6 deletions vlib/sync/atomic2/atomic.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ Implements the atomic operations. For now TCC does not support
the atomic versions on nix so it uses locks to simulate the same behavor.
On windows tcc can simulate with other atomic operations.
The @VROOT/thirdparty/stdatomic contains compability header files
The @VEXEROOT/thirdparty/stdatomic contains compability header files
for stdatomic that supports both nix, windows and c++.
This implementations should be regarded as alpha stage and be
further tested.
*/
#flag windows -I @VROOT/thirdparty/stdatomic/win
#flag linux -I @VROOT/thirdparty/stdatomic/nix
#flag darwin -I @VROOT/thirdparty/stdatomic/nix
#flag freebsd -I @VROOT/thirdparty/stdatomic/nix
#flag solaris -I @VROOT/thirdparty/stdatomic/nix
#flag windows -I @VEXEROOT/thirdparty/stdatomic/win
#flag linux -I @VEXEROOT/thirdparty/stdatomic/nix
#flag darwin -I @VEXEROOT/thirdparty/stdatomic/nix
#flag freebsd -I @VEXEROOT/thirdparty/stdatomic/nix
#flag solaris -I @VEXEROOT/thirdparty/stdatomic/nix
$if linux {
$if tinyc {
// most Linux distributions have /usr/lib/libatomic.so, but Ubuntu uses gcc version specific dir
Expand Down
9 changes: 4 additions & 5 deletions vlib/sync/channels.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module sync
import time
import rand


$if windows {
#flag -I @VROOT/thirdparty/stdatomic/win
#flag -I @VEXEROOT/thirdparty/stdatomic/win
} $else {
#flag -I @VROOT/thirdparty/stdatomic/nix
#flag -I @VEXEROOT/thirdparty/stdatomic/nix
}

$if linux {
Expand Down Expand Up @@ -198,7 +197,7 @@ fn (mut ch Channel) try_push_priv(src voidptr, no_block bool) ChanState {
if C.atomic_load_u16(&ch.closed) != 0 {
return .closed
}
spinloops_sem_, spinloops_ := if no_block { 1, 1 } else { spinloops, spinloops_sem }
spinloops_sem_, spinloops_ := if no_block { 1, 1 } else { sync.spinloops, sync.spinloops_sem }
mut have_swapped := false
for {
mut got_sem := false
Expand Down Expand Up @@ -387,7 +386,7 @@ pub fn (mut ch Channel) try_pop(dest voidptr) ChanState {
}

fn (mut ch Channel) try_pop_priv(dest voidptr, no_block bool) ChanState {
spinloops_sem_, spinloops_ := if no_block { 1, 1 } else { spinloops, spinloops_sem }
spinloops_sem_, spinloops_ := if no_block { 1, 1 } else { sync.spinloops, sync.spinloops_sem }
mut have_swapped := false
mut write_in_progress := false
for {
Expand Down
2 changes: 1 addition & 1 deletion vlib/szip/szip.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module szip

import os

#flag -I @VROOT/thirdparty/zip
#flag -I @VEXEROOT/thirdparty/zip
#include "zip.c"
#include "zip.h"

Expand Down
Loading

0 comments on commit d4f3141

Please sign in to comment.