Skip to content

Commit 35b9dce

Browse files
committed
paths: support multiple paths in C2_LIBDIR
* format: C2_LIBDIR=aa:bb:cc * libs not needed by c2c itself will be moved to secondary archive later
1 parent 14d444a commit 35b9dce

File tree

6 files changed

+42
-33
lines changed

6 files changed

+42
-33
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ see the [installation document](INSTALL.md) for installation on Linux or OSX.
2323
The *C2_LIBDIR* should point to <path_to_c2compiler>/libs
2424
The *C2_PLUGINDIR* may be anywhere and is used by the install_plugins.sh script
2525

26+
All these variables may contain multiple paths, separated by colons (:)
2627

2728
## Bootstrap
2829

common/string_utils.c2

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,24 @@ public fn bool endsWith(const char* text, const char* tail) @(unused) {
5151
usize tlen = strlen(tail);
5252
return (tlen <= len && !memcmp(text + len - tlen, tail, tlen));
5353
}
54+
55+
// NOTE: path is not 0-terminated
56+
public type PathHandler fn void (void* arg, const char* path, u32 len);
57+
58+
public fn void split_paths(const char* input, void* arg, PathHandler handler) @(unused) {
59+
// split by ':'
60+
const char* start = input;
61+
const char* cp = start;
62+
while (1) {
63+
if (*cp == 0) {
64+
if (cp != start) handler(arg, start, (u32)(cp - start));
65+
return;
66+
}
67+
if (*cp == ':') {
68+
if (cp != start) handler(arg, start, (u32)(cp - start));
69+
start = cp+1;
70+
}
71+
cp++;
72+
}
73+
}
74+

compiler/compiler.c2

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import source_mgr;
4141
import string_buffer;
4242
import string_list;
4343
import string_pool;
44+
import string_utils;
4445
import target_info;
4546
import unused_checker;
4647
import utils;
@@ -83,7 +84,7 @@ public type Options struct {
8384
bool asan;
8485
bool msan;
8586
bool ubsan;
86-
u32 libdir; // from environment varible C2_LIBDIR, into auxPool
87+
const char* libdir; // no ownership, from environment varible C2_LIBDIR
8788
char *target_triple;
8889
}
8990

@@ -277,7 +278,10 @@ fn void Compiler.build(Compiler* c,
277278
console.error("images require a build-file");
278279
stdlib.exit(-1);
279280
}
280-
if (c.opts.libdir) c.libdirs.add(c.opts.libdir);
281+
if (c.opts.libdir) {
282+
// parse into multiple, add each to string-pool
283+
string_utils.split_paths(c.opts.libdir, c, handle_path);
284+
}
281285
c.targetInfo.getNative();
282286
}
283287
if (target_str) {
@@ -678,3 +682,12 @@ fn void Compiler.addGlobalDefine(Compiler* c, const char* prefix, const char* ta
678682

679683
c.addFeature(tmp, "1");
680684
}
685+
686+
// NOTE: paths are not 0-terminated
687+
fn void handle_path(void* arg, const char* path, u32 len) {
688+
Compiler* c = arg;
689+
u32 path_idx = c.auxPool.add(path, len, true);
690+
//stdio.printf("PATH [%s]\n", c.auxPool.idx2str(path_idx));
691+
c.libdirs.add(path_idx);
692+
}
693+

compiler/main.c2

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,8 @@ fn void Context.handle_args(Context* c, i32 argc, char** argv) {
510510
}
511511
}
512512

513-
const char* libdir = getenv("C2_LIBDIR");
514-
if (libdir) c.comp_opts.libdir = c.auxPool.addStr(libdir, true);
515-
if (!libdir && !c.opts.build_file) {
513+
c.comp_opts.libdir = getenv("C2_LIBDIR");
514+
if (!c.comp_opts.libdir && !c.opts.build_file) {
516515
console.warn("environment variable C2_LIBDIR not set!");
517516
}
518517
}

env.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
if [ -f libs/libc/stdio.c2i ] ; then
22
echo 'setting C2 development environment'
3+
# NOTE: only add path to libs in this archive for boostrap
34
export C2_LIBDIR=$PWD/libs
45
export C2_PLUGINDIR=$PWD/output/plugins
56
else
67
echo 'setting C2 installation environment'
8+
# NOTE: also adds path to other lib dir
9+
#export C2_LIBDIR=~/c2_libs:~/c2_libs2
710
export C2_LIBDIR=~/c2_libs
811
export C2_PLUGINDIR=~/c2_plugins
912
fi

test/c_generator/lib_lua.c2t

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)