raz / commit f7fb2836

commit
f7fb2836600c9d6e58bffa3fc3f4ceb2181f2b76
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
41dd1445
raz -lib DIR: the standard library is DIR, not the lib beside raz; test/own builds with it

patch · log

5 files changed, +92 -23

doc/compiler.md (history) modified +19 -13

@@ -2213,9 +2213,10 @@
22132213 library (`Sys`, `Files`), and `Files.argCount` and `Files.arg` give it
22142214 its command line.
22152215
2216-- `libraryDir`: the directory of the standard library. Linux's is the
2217- `lib` beside raz, found by `/proc/self/exe` so that a link to raz
2218- works, or, with no `/proc`, beside argument 0.
2216+- `libraryDir`: the directory of the standard library when `-lib`
2217+ doesn't name one. Linux's is the `lib` beside raz, found by
2218+ `/proc/self/exe` so that a link to raz works, or, with no `/proc`,
2219+ beside argument 0.
22192220 - `cLibrary`: `CLib = (none, glibc, musl)`, the C library a program that
22202221 uses C is linked against when `-libc` doesn't say. `none` says the
22212222 host can't make such a program, and `Raz` refuses one when it finds
@@ -2294,6 +2295,13 @@
22942295 puts them between those and the standard library, for both finding
22952296 modules and checking duplicate names. No subdirectories are searched.
22962297
2298+`-lib dir` makes `dir` the library: `Raz.raz` reads it with the other
2299+options, stops with "-lib dir: no such directory" if `Sys.access` can't
2300+reach it, and gives it to `Parse.setLibDir` in place of
2301+`Host.libraryDir()`. It changes nothing else: `searchDir` still puts
2302+the library last, after `-I` and `RAZ_PATH`, and the duplicate check
2303+(a symbolic link to one of the two files chooses it) is as before.
2304+
22972305 ## A program with its own Rt
22982306
22992307 A hosted program uses `lib/Rt.raz`. A freestanding one, a kernel's
@@ -2302,16 +2310,14 @@
23022310 code disagree, the code (`Gen.entryPoint`, `Raz.raz`) is right.
23032311
23042312 **Giving a program its own `Rt`.** A program has one module of each
2305-name, and the library is the `lib/` beside the compiler (`Raz.raz` finds
2306-it through `/proc/self/exe`), so an `Rt.raz` beside the main file meets
2307-`lib/Rt.raz` and is refused. What works today is staging: copy `raz`
2308-beside a `lib/` holding the program's own modules, and build with that
2309-copy. The library is then all of what is in that `lib/`, and nothing of
2310-raz's unless the program copies or links it there (a symbolic link
2311-chooses a module). `test/own` does it: `check.sh` copies `raz` to
2312-`build/check/own/`, with `test/own/lib/Rt.raz` as its whole library,
2313-and builds `test/own/Own.raz` and `OwnFail.raz` with it, under `-bare
2314--s`.
2313+name, and the library is `lib/` beside the compiler, so an `Rt.raz`
2314+beside the main file meets `lib/Rt.raz` and is refused. `raz -lib DIR`
2315+makes `DIR` the library instead: the program's own `Rt` and `Sys`, and
2316+symbolic links to whichever of raz's modules it takes (a link chooses a
2317+module, as always). The library is all of what is in `DIR`, and nothing
2318+of raz's unless it is linked there. `test/own` does it: `check.sh`
2319+builds `test/own/Own.raz` and `OwnFail.raz` with `-lib test/own/lib`,
2320+whose `Rt.raz` is the whole library, under `-bare -s`.
23152321
23162322 **What `Rt` must declare.** `Raz.raz` finds each name in `Rt`'s scope
23172323 (`objIn`) and stops with "Rt has no X" where one is missing:

doc/raz.1 (history) modified +24 -1

@@ -42,7 +42,9 @@
4242 .Pa lib/
4343 beside the
4444 .Nm
45-executable, whose modules
45+executable (or the one
46+.Fl lib
47+names), whose modules
4648 .Xr raz-lib 3
4749 says.
4850 A program has one module of each name: a module found in two of these
@@ -98,6 +100,27 @@
98100 a second line says the raz the library was written for and this one:
99101 .Ql (a library written for raz 0.18; this is raz 0.21) .
100102 The compiler only reads the file; it never refuses to build for it.
103+.It Fl lib Ar dir
104+The standard library is
105+.Ar dir ,
106+not the
107+.Pa lib/
108+beside the
109+.Nm
110+executable.
111+It is searched last, after the main module's directory, the
112+.Fl I
113+directories and the user library directories, as the default library is;
114+the duplicate-module rule and its symbolic-link exception apply to it
115+unchanged.
116+It is an error if
117+.Ar dir
118+cannot be reached.
119+A kernel's library holds its own
120+.Pa Rt.raz
121+and
122+.Pa Sys.raz ,
123+with symbolic links to the modules of raz's own library that it takes.
101124 .It Fl Werror
102125 A warning counts as an error.
103126 .It Fl S

src/Raz.raz (history) modified +12 -1

@@ -126,6 +126,8 @@
126126 Out.str("options:\n");
127127 Out.str(" -o file the program's file, Main without .raz if left out\n");
128128 Out.str(" -I dir looks for imported modules in dir too, after Main.raz's own\n");
129+ Out.str(" -lib dir the standard library is dir, not the lib beside raz; it is\n");
130+ Out.str(" searched last, after -I and RAZ_PATH\n");
129131 Out.str(" -Werror a warning counts as an error\n");
130132 Out.str(" -S lists the main module's code, under each line of source\n");
131133 Out.str(" -s strips symbols, line numbers, the places a failure is told\n");
@@ -230,9 +232,11 @@
230232 i, first, entry, last, base: INT;
231233 m, rt, thread: ^Sym.Module; mainObj: ^Sym.Obj;
232234 run, noProfile, listing, dynamic, libcSaid, ok, bare: BOOL; err: ERROR;
235+ libDir: []const U8;
233236 begin
234237 path := "";
235238 outPath := "";
239+ libDir := "";
236240 noProfile := false;
237241 bare := false;
238242 listing := false;
@@ -245,6 +249,12 @@
245249 INC(i);
246250 if Parse.numInc > 15 then Diag.fatal("more than 16 -I directories"); end;
247251 Parse.addIncDir(Files.arg(i));
252+ elsif s = "-lib" then
253+ INC(i);
254+ libDir := Files.arg(i);
255+ if (LEN(libDir) = 0) or (Sys.access(libDir, {}) # 0) then
256+ Diag.fatal(say1("-lib {}: no such directory", libDir));
257+ end;
248258 elsif s = "-o" then
249259 INC(i);
250260 outPath := Files.arg(i);
@@ -300,7 +310,8 @@
300310 end;
301311 if not libcSaid then Elf.setMusl(Host.cLibrary() = Host.musl); end;
302312 Parse.setVersion(Version.Text);
303- Parse.setLibDir(Host.libraryDir());
313+ if LEN(libDir) = 0 then libDir := Host.libraryDir(); end;
314+ Parse.setLibDir(libDir);
304315 userLibraries();
305316 if LEN(outPath) = 0 then
306317 outPath := path;

test/check.sh (history) modified +6 -8

@@ -153,16 +153,14 @@
153153 && cmp -s $out/Index.out $out/IndexBare.out; then pass=$((pass + 1))
154154 else echo "FAIL raz -bare: status $status"; cat $out/Bare.out $out/Bare.err $out/IndexBare.out; fail=$((fail + 1)); fi
155155
156-# a program with its own Rt (doc/compiler.md): the compiler copied
157-# beside a lib/ of nothing but test/own/lib/Rt.raz, whose exit and
158-# fail make their system calls themselves; Own ends with main's 3 after
159-# saying hello, OwnFail with 2 after Rt.fail's kind 0, an index
156+# a program with its own Rt (doc/compiler.md): raz -lib of nothing but
157+# test/own/lib/Rt.raz, whose exit and fail make their system calls
158+# themselves; Own ends with main's 3 after saying hello, OwnFail with 2
159+# after Rt.fail's kind 0, an index
160160 rm -rf $out/own; mkdir -p $out/own
161-cp $raz $out/own/raz
162-cp -r test/own/lib $out/own/lib
163-$out/own/raz -Werror -bare -s -o $out/own/Own test/own/Own.raz
161+$raz -lib test/own/lib -Werror -bare -s -o $out/own/Own test/own/Own.raz
164162 status=$( { ( exec $out/own/Own ) > $out/own/Own.out 2>&1; echo $?; } 2>/dev/null )
165-$out/own/raz -Werror -bare -s -o $out/own/OwnFail test/own/OwnFail.raz
163+$raz -lib test/own/lib -Werror -bare -s -o $out/own/OwnFail test/own/OwnFail.raz
166164 statusFail=$( { ( exec $out/own/OwnFail ) > $out/own/OwnFail.out 2>&1; echo $?; } 2>/dev/null )
167165 if [ $status = 3 ] && [ $statusFail = 2 ] && [ "$(cat $out/own/Own.out)" = hello ] \
168166 && [ "$(cat $out/own/OwnFail.out)" = 'check failed: 0' ]; then pass=$((pass + 1))

test/library-path.sh (history) modified +31 -0

@@ -177,6 +177,35 @@
177177 fails "module Out is in"
178178 }
179179
180+# -lib DIR: a copy of the library, which the program uses instead of the
181+# one beside raz; PathLib comes from -I, so the library is searched last
182+t_lib_replaces_standard_library() {
183+ cp -R "$(dirname "$raz")/lib" "$root/mylib"
184+ library "$root/inc"
185+ succeeds -I "$root/inc" -lib "$root/mylib"
186+}
187+
188+# -lib changes where the library is, not the order: a module in both the
189+# library and an -I directory is found twice
190+t_lib_is_searched_last() {
191+ cp -R "$(dirname "$raz")/lib" "$root/mylib"
192+ library "$root/inc"
193+ echo "module Out; end Out." >"$root/inc/Out.raz"
194+ fails "module Out is in" -I "$root/inc" -lib "$root/mylib"
195+}
196+
197+# RAZ_PATH still finds PathLib, the library coming after it
198+t_lib_leaves_user_path_alone() {
199+ cp -R "$(dirname "$raz")/lib" "$root/mylib"
200+ library "$root/user"
201+ RAZ_PATH="$root/user"; export RAZ_PATH
202+ succeeds -lib "$root/mylib"
203+}
204+
205+t_lib_missing_directory() {
206+ fails "-lib $root/nowhere: no such directory" -lib "$root/nowhere"
207+}
208+
180209 t_user_paths_do_not_consume_include_slots() {
181210 library "$default"
182211 flags=
@@ -266,6 +295,8 @@
266295 t_no_path_expansion t_target_file_and_interface \
267296 t_duplicate_main_and_include t_duplicate_user_directories \
268297 t_duplicate_standard_library \
298+ t_lib_replaces_standard_library t_lib_is_searched_last \
299+ t_lib_leaves_user_path_alone t_lib_missing_directory \
269300 t_user_paths_do_not_consume_include_slots \
270301 t_trailing_slash_keeps_sibling_paths t_hard_link_chooses_same_module \
271302 t_equal_contents_do_not_choose_distinct_module \