|
1 | 1 | let version = "4.06.1+BS"
|
2 | 2 |
|
3 |
| -(* This resolves the location of the standard library starting from the location of bsc.exe, |
4 |
| - handling different supported package layouts. *) |
| 3 | +(* To determine the standard library path in a reliable way that works with all package managers / |
| 4 | + package directory layouts, we need to do it on the JS side, see cli/common/stdlib.js. |
| 5 | + We pass the directory to the compiler exe via the environment variable RESCRIPT_STDLIB. *) |
5 | 6 | let standard_library =
|
6 |
| - let build_path rest path = |
7 |
| - String.concat Filename.dir_sep (List.rev_append rest path) |
8 |
| - in |
9 |
| - match |
10 |
| - Sys.executable_name |> Filename.dirname |
11 |
| - |> String.split_on_char Filename.dir_sep.[0] |
12 |
| - |> List.rev |
13 |
| - with |
14 |
| - (* 1. Packages installed via pnpm |
15 |
| - - bin: node_modules/.pnpm/@[email protected]/node_modules/@rescript/darwin-arm64/bin |
16 |
| - - stdlib: node_modules/rescript/lib/ocaml (symlink) |
17 |
| - *) |
18 |
| - | "bin" :: _platform :: "@rescript" :: "node_modules" :: _package :: ".pnpm" |
19 |
| - :: "node_modules" :: rest -> |
20 |
| - build_path rest ["node_modules"; "rescript"; "lib"; "ocaml"] |
21 |
| - (* 2. Packages installed via npm |
22 |
| - - bin: node_modules/@rescript/{platform}/bin |
23 |
| - - stdlib: node_modules/rescript/lib/ocaml |
24 |
| - *) |
25 |
| - | "bin" :: _platform :: "@rescript" :: "node_modules" :: rest -> |
26 |
| - build_path rest ["node_modules"; "rescript"; "lib"; "ocaml"] |
27 |
| - (* 3. Several other cases that can occur in local development, e.g. |
28 |
| - - bin: <repo>/packages/@rescript/{platform}/bin, <repo>/_build/install/default/bin |
29 |
| - - stdlib: <repo>/lib/ocaml |
30 |
| - *) |
31 |
| - | _ :: _ :: _ :: _ :: rest -> build_path rest ["lib"; "ocaml"] |
32 |
| - | _ -> "" |
| 7 | + match Sys.getenv_opt "RESCRIPT_STDLIB" with |
| 8 | + | Some path -> path |
| 9 | + | None -> "" |
33 | 10 |
|
34 | 11 | let standard_library_default = standard_library
|
35 | 12 |
|
|
0 commit comments