Skip to content

Commit 6366814

Browse files
committed
Bring back advanced logic for finding runtime path
1 parent 99382ad commit 6366814

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

compiler/ext/config.ml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
(* This resolves the location of the standard library starting from the location of bsc.exe
2-
(@rescript/{platform}/bin/bsc.exe), assuming the standard npm node_modules layout.
3-
4-
For pnpm and other special node_modules layouts, the correct path shall be passed
5-
via the `-runtime` flag. *)
2+
(@rescript/{platform}/bin/bsc.exe), handling different supported package layouts. *)
63
let standard_library =
7-
let exe_path = Sys.executable_name in
8-
let bin_dir = Filename.dirname exe_path in
9-
let platform_dir = Filename.dirname bin_dir in
10-
let rescript_dir = Filename.dirname platform_dir in
11-
let ( // ) = Filename.concat in
12-
rescript_dir // "runtime" // "lib" // "ocaml"
4+
let build_path rest path =
5+
String.concat Filename.dir_sep (List.rev_append rest path)
6+
in
7+
match
8+
Sys.executable_name |> Filename.dirname
9+
|> String.split_on_char Filename.dir_sep.[0]
10+
|> List.rev
11+
with
12+
(* 1. Packages installed via pnpm
13+
- bin: node_modules/.pnpm/@[email protected]/node_modules/@rescript/darwin-arm64/bin
14+
- stdlib: node_modules/@rescript/runtime/lib/ocaml (symlink)
15+
*)
16+
| "bin" :: _platform :: "@rescript" :: "node_modules" :: _package :: ".pnpm"
17+
:: "node_modules" :: rest ->
18+
build_path rest ["node_modules"; "@rescript"; "runtime"; "lib"; "ocaml"]
19+
(* 2. Packages installed via npm
20+
- bin: node_modules/@rescript/{platform}/bin
21+
- stdlib: node_modules/@rescript/runtime/lib/ocaml
22+
*)
23+
| "bin" :: _platform :: "@rescript" :: "node_modules" :: rest ->
24+
build_path rest ["node_modules"; "@rescript"; "runtime"; "lib"; "ocaml"]
25+
(* 3. Several other cases that can occur in local development, e.g.
26+
- bin: <repo>/packages/@rescript/{platform}/bin, <repo>/_build/install/default/bin
27+
- stdlib: <repo>/packages/@rescript/runtime/lib/ocaml
28+
*)
29+
| _ :: _ :: _ :: _ :: rest ->
30+
build_path rest ["packages"; "@rescript"; "runtime"; "lib"; "ocaml"]
31+
| _ -> ""
1332

1433
let cmi_magic_number = "Caml1999I022"
1534

0 commit comments

Comments
 (0)