raz -lib DIR: the standard library is DIR, not the lib beside raz; test/own builds with it
| @@ -2213,9 +2213,10 @@ | ||
| 2213 | 2213 | library (`Sys`, `Files`), and `Files.argCount` and `Files.arg` give it |
| 2214 | 2214 | its command line. |
| 2215 | 2215 | |
| 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. | |
| 2219 | 2220 | - `cLibrary`: `CLib = (none, glibc, musl)`, the C library a program that |
| 2220 | 2221 | uses C is linked against when `-libc` doesn't say. `none` says the |
| 2221 | 2222 | host can't make such a program, and `Raz` refuses one when it finds |
| @@ -2294,6 +2295,13 @@ | ||
| 2294 | 2295 | puts them between those and the standard library, for both finding |
| 2295 | 2296 | modules and checking duplicate names. No subdirectories are searched. |
| 2296 | 2297 | |
| 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 | + | |
| 2297 | 2305 | ## A program with its own Rt |
| 2298 | 2306 | |
| 2299 | 2307 | A hosted program uses `lib/Rt.raz`. A freestanding one, a kernel's |
| @@ -2302,16 +2310,14 @@ | ||
| 2302 | 2310 | code disagree, the code (`Gen.entryPoint`, `Raz.raz`) is right. |
| 2303 | 2311 | |
| 2304 | 2312 | **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`. | |
| 2315 | 2321 | |
| 2316 | 2322 | **What `Rt` must declare.** `Raz.raz` finds each name in `Rt`'s scope |
| 2317 | 2323 | (`objIn`) and stops with "Rt has no X" where one is missing: |
| @@ -42,7 +42,9 @@ | ||
| 42 | 42 | .Pa lib/ |
| 43 | 43 | beside the |
| 44 | 44 | .Nm |
| 45 | -executable, whose modules | |
| 45 | +executable (or the one | |
| 46 | +.Fl lib | |
| 47 | +names), whose modules | |
| 46 | 48 | .Xr raz-lib 3 |
| 47 | 49 | says. |
| 48 | 50 | A program has one module of each name: a module found in two of these |
| @@ -98,6 +100,27 @@ | ||
| 98 | 100 | a second line says the raz the library was written for and this one: |
| 99 | 101 | .Ql (a library written for raz 0.18; this is raz 0.21) . |
| 100 | 102 | 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. | |
| 101 | 124 | .It Fl Werror |
| 102 | 125 | A warning counts as an error. |
| 103 | 126 | .It Fl S |
| @@ -126,6 +126,8 @@ | ||
| 126 | 126 | Out.str("options:\n"); |
| 127 | 127 | Out.str(" -o file the program's file, Main without .raz if left out\n"); |
| 128 | 128 | 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"); | |
| 129 | 131 | Out.str(" -Werror a warning counts as an error\n"); |
| 130 | 132 | Out.str(" -S lists the main module's code, under each line of source\n"); |
| 131 | 133 | Out.str(" -s strips symbols, line numbers, the places a failure is told\n"); |
| @@ -230,9 +232,11 @@ | ||
| 230 | 232 | i, first, entry, last, base: INT; |
| 231 | 233 | m, rt, thread: ^Sym.Module; mainObj: ^Sym.Obj; |
| 232 | 234 | run, noProfile, listing, dynamic, libcSaid, ok, bare: BOOL; err: ERROR; |
| 235 | + libDir: []const U8; | |
| 233 | 236 | begin |
| 234 | 237 | path := ""; |
| 235 | 238 | outPath := ""; |
| 239 | + libDir := ""; | |
| 236 | 240 | noProfile := false; |
| 237 | 241 | bare := false; |
| 238 | 242 | listing := false; |
| @@ -245,6 +249,12 @@ | ||
| 245 | 249 | INC(i); |
| 246 | 250 | if Parse.numInc > 15 then Diag.fatal("more than 16 -I directories"); end; |
| 247 | 251 | 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; | |
| 248 | 258 | elsif s = "-o" then |
| 249 | 259 | INC(i); |
| 250 | 260 | outPath := Files.arg(i); |
| @@ -300,7 +310,8 @@ | ||
| 300 | 310 | end; |
| 301 | 311 | if not libcSaid then Elf.setMusl(Host.cLibrary() = Host.musl); end; |
| 302 | 312 | Parse.setVersion(Version.Text); |
| 303 | - Parse.setLibDir(Host.libraryDir()); | |
| 313 | + if LEN(libDir) = 0 then libDir := Host.libraryDir(); end; | |
| 314 | + Parse.setLibDir(libDir); | |
| 304 | 315 | userLibraries(); |
| 305 | 316 | if LEN(outPath) = 0 then |
| 306 | 317 | outPath := path; |
| @@ -153,16 +153,14 @@ | ||
| 153 | 153 | && cmp -s $out/Index.out $out/IndexBare.out; then pass=$((pass + 1)) |
| 154 | 154 | else echo "FAIL raz -bare: status $status"; cat $out/Bare.out $out/Bare.err $out/IndexBare.out; fail=$((fail + 1)); fi |
| 155 | 155 | |
| 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 | |
| 160 | 160 | 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 | |
| 164 | 162 | 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 | |
| 166 | 164 | statusFail=$( { ( exec $out/own/OwnFail ) > $out/own/OwnFail.out 2>&1; echo $?; } 2>/dev/null ) |
| 167 | 165 | if [ $status = 3 ] && [ $statusFail = 2 ] && [ "$(cat $out/own/Own.out)" = hello ] \ |
| 168 | 166 | && [ "$(cat $out/own/OwnFail.out)" = 'check failed: 0' ]; then pass=$((pass + 1)) |
| @@ -177,6 +177,35 @@ | ||
| 177 | 177 | fails "module Out is in" |
| 178 | 178 | } |
| 179 | 179 | |
| 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 | + | |
| 180 | 209 | t_user_paths_do_not_consume_include_slots() { |
| 181 | 210 | library "$default" |
| 182 | 211 | flags= |
| @@ -266,6 +295,8 @@ | ||
| 266 | 295 | t_no_path_expansion t_target_file_and_interface \ |
| 267 | 296 | t_duplicate_main_and_include t_duplicate_user_directories \ |
| 268 | 297 | 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 \ | |
| 269 | 300 | t_user_paths_do_not_consume_include_slots \ |
| 270 | 301 | t_trailing_slash_keeps_sibling_paths t_hard_link_chooses_same_module \ |
| 271 | 302 | t_equal_contents_do_not_choose_distinct_module \ |