|  | 
| 1 |  | -(* This resolves the location of the standard library starting from the location of bsc.exe, | 
| 2 |  | -  handling different supported package layouts. *) | 
|  | 1 | +(* To determine the standard library path in a reliable way that works with all package managers / | 
|  | 2 | +   package directory layouts, we need to do it on the JS side, see cli/common/stdlib.js. | 
|  | 3 | +   We pass the directory to the compiler exe via the environment variable RESCRIPT_STDLIB. *) | 
| 3 | 4 | let standard_library = | 
| 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/@rescript+darwin-arm64@12.0.0-alpha.13/node_modules/@rescript/darwin-arm64/bin | 
| 14 |  | -     - stdlib: node_modules/rescript/lib/ocaml (symlink) | 
| 15 |  | -  *) | 
| 16 |  | -  | "bin" :: _platform :: "@rescript" :: "node_modules" :: _package :: ".pnpm" | 
| 17 |  | -    :: "node_modules" :: rest -> | 
| 18 |  | -    build_path rest ["node_modules"; "rescript"; "lib"; "ocaml"] | 
| 19 |  | -  (* 2. Packages installed via npm | 
| 20 |  | -     - bin:    node_modules/@rescript/{platform}/bin | 
| 21 |  | -     - stdlib: node_modules/rescript/lib/ocaml | 
| 22 |  | -  *) | 
| 23 |  | -  | "bin" :: _platform :: "@rescript" :: "node_modules" :: rest -> | 
| 24 |  | -    build_path rest ["node_modules"; "rescript"; "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>/lib/ocaml | 
| 28 |  | -  *) | 
| 29 |  | -  | _ :: _ :: _ :: _ :: rest -> build_path rest ["lib"; "ocaml"] | 
| 30 |  | -  | _ -> "" | 
|  | 5 | +  match Sys.getenv_opt "RESCRIPT_STDLIB" with | 
|  | 6 | +  | Some path -> path | 
|  | 7 | +  | None -> "" | 
| 31 | 8 | 
 | 
| 32 | 9 | let cmi_magic_number = "Caml1999I022" | 
| 33 | 10 | 
 | 
|  | 
0 commit comments