|
1 | 1 | let version = "4.06.1+BS" |
2 | 2 |
|
3 | | -(* FIXME: Unreliable resolution *) |
| 3 | +(* This resolves the location of the standard library starting from the location of bsc.exe, |
| 4 | + handling different supported package layouts. *) |
4 | 5 | let standard_library = |
5 | | - let ( // ) = Filename.concat in |
6 | | - let exe_path = Sys.executable_name in |
7 | | - if Ext_string.contain_substring exe_path ("node_modules" // "@rescript") then |
8 | | - (* node_modules/@rescript/{platform}/bin *) |
9 | | - Filename.dirname exe_path // Filename.parent_dir_name |
10 | | - // Filename.parent_dir_name // Filename.parent_dir_name // "rescript" |
11 | | - // "lib" // "ocaml" |
12 | | - else if Ext_string.contain_substring exe_path ("node_modules" // "rescript") |
13 | | - then |
14 | | - (* node_modules/rescript/{platform} *) |
15 | | - Filename.dirname exe_path // Filename.parent_dir_name // "lib" // "ocaml" |
16 | | - else |
17 | | - (* git repo: rescript/packages/@rescript/{platform}/bin *) |
18 | | - Filename.dirname exe_path // Filename.parent_dir_name |
19 | | - // Filename.parent_dir_name // Filename.parent_dir_name |
20 | | - // Filename.parent_dir_name // "lib" // "ocaml" |
| 6 | + let build_path rest path = |
| 7 | + String.concat Filename.dir_sep (List.rev 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. Local development in the `rescript` repo, installed to packages dir |
| 28 | + - bin: <repo>/packages/@rescript/{platform}/bin |
| 29 | + - stdlib: <repo>/lib/ocaml |
| 30 | + *) |
| 31 | + | "bin" :: _platform :: "@rescript" :: "packages" :: rest -> |
| 32 | + build_path rest ["lib"; "ocaml"] |
| 33 | + (* 4. Local development in the `rescript` repo, from dune build dir |
| 34 | + - bin: <repo>/_build/install/default/bin |
| 35 | + - stdlib: <repo>/lib/ocaml |
| 36 | + *) |
| 37 | + | "bin" :: "default" :: "install" :: "_build" :: rest -> |
| 38 | + build_path rest ["lib"; "ocaml"] |
| 39 | + | _ -> |
| 40 | + (* Not found, this can occur e.g. for the syntax tests *) |
| 41 | + "" |
21 | 42 |
|
22 | 43 | let standard_library_default = standard_library |
23 | 44 |
|
|
0 commit comments