Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,16 @@ jobs:
name: binaries-${{ matrix.node-target }}
path: packages/@rescript/${{ matrix.node-target }}/bin

- name: "Upload artifacts: lib/ocaml"
- name: "Upload artifacts: lib/rescript"
if: matrix.upload_libs
uses: actions/upload-artifact@v7
with:
name: lib-ocaml
name: lib-rescript
path: |
packages/@rescript/runtime/lib/ocaml
!packages/@rescript/runtime/lib/ocaml/*.ast
!packages/@rescript/runtime/lib/ocaml/*.iast
packages/@rescript/runtime/lib/rescript
!packages/@rescript/runtime/lib/rescript/*.ast
!packages/@rescript/runtime/lib/rescript/*.iast
!packages/@rescript/runtime/lib/rescript/compiler-info.json

- name: Select API docs website branch
id: api-docs-plan
Expand Down Expand Up @@ -423,7 +424,7 @@ jobs:
- name: Download artifacts
uses: actions/download-artifact@v8
with:
pattern: "@(binaries-*|lib-ocaml)"
pattern: "@(binaries-*|lib-rescript)"

- name: Move artifacts into packages
run: .github/workflows/moveArtifacts.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/moveArtifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ check_statically_linked() {
}

# rescript
mv lib-ocaml packages/@rescript/runtime/lib/ocaml
mv lib-rescript packages/@rescript/runtime/lib/rescript

# @rescript/{target}
chmod +x binaries-*/*.exe
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
- name: Download artifacts
uses: actions/download-artifact@v8
with:
pattern: "@(binaries-*|lib-ocaml)"
pattern: "@(binaries-*|lib-rescript)"

- name: Move artifacts into packages
run: .github/workflows/moveArtifacts.sh
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ node_modules
_coverage/
bisect*.coverage

lib/ocaml
lib/rescript
tests/build_tests/*/lib/
#ignore temporary directory
*.goog.js
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ To view the typed tree of the file run:
### Project

```sh
make artifacts # Build compiler and standard library and populate lib/ocaml
make artifacts # Build compiler and standard library and populate lib/rescript
npm link
cd myProject
npm install
Expand Down
8 changes: 4 additions & 4 deletions analysis/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Options:

createInterface: print to stdout the interface file for src/MyFile.res

./rescript-editor-analysis.exe createInterface src/MyFile.res lib/bs/src/MyFile.cmi
./rescript-editor-analysis.exe createInterface src/MyFile.res lib/rescript/MyFile.cmi

format: print to stdout the formatted version of the provided file

Expand Down Expand Up @@ -127,10 +127,10 @@ let main () =
let uri = Uri.from_path root_path in
match Packages.find_root ~uri (Hashtbl.create 0) with
| Some (`Bs root_path) -> (
match Build_system.get_lib_bs root_path with
match Build_system.get_artifact_dir root_path with
| None -> print_endline "\"ERR\""
| Some lib_bs ->
Cache.delete_cache (Cache.target_file_from_lib_bs lib_bs);
| Some artifact_dir ->
Cache.delete_cache (Cache.target_file_from_artifact_dir artifact_dir);
print_endline "\"OK\"")
| _ -> print_endline "\"ERR: Did not find root \"")
| [_; "completion"; path; line; col; current_file] ->
Expand Down
2 changes: 1 addition & 1 deletion analysis/reanalyze/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Dead code analysis and other experimental analyses for ReScript.
rescript-tools reanalyze -config

# Run DCE analysis on specific CMT directory
rescript-tools reanalyze -dce-cmt path/to/lib/bs
rescript-tools reanalyze -dce-cmt path/to/lib/rescript

# Run all analyses
rescript-tools reanalyze -all
Expand Down
5 changes: 3 additions & 2 deletions analysis/reanalyze/src/paths.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ type cmt_scan_entry = {
This is a v2 extension produced by `rewatch` to support monorepos without requiring
reanalyze-side package resolution.

The scan plan is a list of build roots (usually `<pkg>/lib/bs`) relative to the project root,
The scan plan is a list of build roots (`<pkg>/lib/rescript`) relative to the project root,
plus a list of subdirectories (relative to that build root) to scan for `.cmt/.cmti`.
Build roots are flat, so the subdirectories are empty and each build root is scanned itself.

If missing, returns the empty list and callers should fall back to legacy behavior. *)

let read_cmt_scan () =
let source_dirs_file =
["lib"; "bs"; ".sourcedirs.json"]
["lib"; "rescript"; ".sourcedirs.json"]
|> List.fold_left Filename.concat run_config.bsb_project_root
in
let get_fn key fn json =
Expand Down
3 changes: 3 additions & 0 deletions analysis/reanalyze/src/reanalyze.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ let collect_cmt_file_paths ~cmt_root : string list =
let skip_dir =
let base = Filename.basename dir in
base = "node_modules" || base = "_esy"
(* The editor's copies of compiled files. *)
|| base = "incremental"
&& Filename.basename (Filename.dirname dir) = "rescript"
in
if (not skip_dir) && Sys.file_exists abs_dir then
if Sys.is_directory abs_dir then
Expand Down
7 changes: 5 additions & 2 deletions analysis/src/build_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ let get_runtime_dir root_path =
None))
| true -> Some root_path

let get_lib_bs path = Files.if_exists (path /+ "lib" /+ "bs")
(* A package's compiled files, flat in lib/rescript. *)
let get_artifact_dir path = Files.if_exists (path /+ "lib" /+ "rescript")

(* The runtime's compiled files. Its sources are at the root of the runtime
package, see [get_runtime_dir]. *)
let get_stdlib base =
match get_runtime_dir base with
| None -> None
| Some runtime_dir -> Some (runtime_dir /+ "lib" /+ "ocaml")
| Some runtime_dir -> Some (runtime_dir /+ "lib" /+ "rescript")
10 changes: 5 additions & 5 deletions analysis/src/cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ let read_cache filename =

let delete_cache filename = try Sys.remove filename with _ -> ()

let target_file_from_lib_bs lib_bs =
Filename.concat lib_bs ".project-files-cache"
let target_file_from_artifact_dir artifact_dir =
Filename.concat artifact_dir ".project-files-cache"

let cache_project (package : package) =
let cached =
Expand All @@ -34,9 +34,9 @@ let cache_project (package : package) =
paths_for_module = package.paths_for_module;
}
in
match Build_system.get_lib_bs package.root_path with
match Build_system.get_artifact_dir package.root_path with
| None -> print_endline "\"ERR\""
| Some lib_bs ->
let target_file = target_file_from_lib_bs lib_bs in
| Some artifact_dir ->
let target_file = target_file_from_artifact_dir artifact_dir in
write_cache target_file cached;
print_endline "\"OK\""
2 changes: 1 addition & 1 deletion analysis/src/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ let test ~state ~path =
let ( ++ ) = concat in
let name = chop_extension (basename path) ^ ".cmi" in
let dir = dirname path in
dir ++ parent_dir_name ++ "lib" ++ "bs" ++ "src" ++ name
dir ++ parent_dir_name ++ "lib" ++ "rescript" ++ name
in
create_interface ~path ~cmi_file
| "ref" ->
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/cmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let full_for_incremental_cmt ~package ~module_name ~uri =
if !Cfg.in_incremental_typechecking_mode then
let path = Uri.to_path uri in
let incremental_cmt_path =
package.root_path ^ "/lib/bs/___incremental" ^ "/" ^ module_name
package.root_path ^ "/lib/rescript/incremental" ^ "/" ^ module_name
^
match Files.classify_source_file path with
| Resi -> ".cmti"
Expand Down
67 changes: 37 additions & 30 deletions analysis/src/find_files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,27 @@ let get_public config =
|> List.filter_map Yojson_helpers.string_opt
|> String_set.of_list))

let collect_files directory =
let all_files = Files.read_directory directory in
(* Pairs the compiled files in [compiled_directory] with the sources of the same
name in [source_directory], as the runtime ships them. *)
let collect_files ~compiled_directory ~source_directory =
let compileds =
all_files |> List.filter is_compiled_file |> filter_duplicates
Files.read_directory compiled_directory
|> List.filter is_compiled_file
|> filter_duplicates
in
let sources =
Files.read_directory source_directory
|> List.filter is_source_file |> filter_duplicates
in
let sources = all_files |> List.filter is_source_file |> filter_duplicates in
compileds
|> Utils.filter_map (fun path ->
let mod_name = get_name path in
let cmt = directory /+ path in
let cmt = compiled_directory /+ path in
let res_opt =
Utils.find
(fun name ->
if get_name name = mod_name then Some (directory /+ name) else None)
if get_name name = mod_name then Some (source_directory /+ name)
else None)
sources
in
match res_opt with
Expand All @@ -155,7 +162,7 @@ let collect_files directory =
.sourcedirs.json when available. If a package is not listed there, analysis
falls back to walking up node_modules from the project root. *)
let read_sourcedirs_package_roots base =
let source_dirs_file = base /+ "lib" /+ "bs" /+ ".sourcedirs.json" in
let source_dirs_file = base /+ "lib" /+ "rescript" /+ ".sourcedirs.json" in
let read_package_entry = function
| `List [`String name; `String path] ->
let path = if Filename.is_relative path then base /+ path else path in
Expand All @@ -180,7 +187,8 @@ let find_package_root ~base ~sourcedirs_package_roots name =
| _ -> Module_resolution.resolve_node_module_path ~start_path:base name

(* returns a list of (absolute path to cmt(i), relative path from base to source file) *)
let find_project_files ~public ~namespace ~path ~source_directories ~lib_bs =
let find_project_files ~public ~namespace ~path ~source_directories
~artifact_dir =
let dirs =
source_directories |> List.map (Filename.concat path) |> String_set.of_list
in
Expand Down Expand Up @@ -210,11 +218,12 @@ let find_project_files ~public ~namespace ~path ~source_directories ~lib_bs =
let module_name = get_name file in
let resi = Hashtbl.find_opt interfaces module_name in
Hashtbl.remove interfaces module_name;
let base = compiled_base_name ~namespace (Files.relpath path file) in
(* Compiled files are flat in the artifact directory. *)
let base = compiled_base_name ~namespace (Filename.basename file) in
match resi with
| Some resi ->
let cmti = (lib_bs /+ base) ^ ".cmti" in
let cmt = (lib_bs /+ base) ^ ".cmt" in
let cmti = (artifact_dir /+ base) ^ ".cmti" in
let cmt = (artifact_dir /+ base) ^ ".cmt" in
if Files.exists cmti then
if Files.exists cmt then
(* Log.log("Intf and impl " ++ cmti ++ " " ++ cmt) *)
Expand All @@ -224,13 +233,14 @@ let find_project_files ~public ~namespace ~path ~source_directories ~lib_bs =
else None
else (
(* Log.log("Just intf " ++ cmti) *)
Log.log ("Bad source file (no cmt/cmti/cmi) " ^ (lib_bs /+ base));
Log.log
("Bad source file (no cmt/cmti/cmi) " ^ (artifact_dir /+ base));
None)
| None ->
let cmt = (lib_bs /+ base) ^ ".cmt" in
let cmt = (artifact_dir /+ base) ^ ".cmt" in
if Files.exists cmt then Some (module_name, Impl {cmt; res = file})
else (
Log.log ("Bad source file (no cmt/cmi) " ^ (lib_bs /+ base));
Log.log ("Bad source file (no cmt/cmi) " ^ (artifact_dir /+ base));
None))
else None)
in
Expand All @@ -253,7 +263,7 @@ let find_project_files ~public ~namespace ~path ~source_directories ~lib_bs =
| None -> result
| Some namespace ->
let module_name = name_space_to_name namespace in
let cmt = (lib_bs /+ namespace) ^ ".cmt" in
let cmt = (artifact_dir /+ namespace) ^ ".cmt" in
Log.log ("adding namespace " ^ namespace ^ " : " ^ module_name ^ " : " ^ cmt);
(module_name, Namespace {cmt}) :: result

Expand Down Expand Up @@ -303,20 +313,13 @@ let find_dependency_files base config =
get_source_directories ~include_dev:false ~base_dir:path
inner
in
match Build_system.get_lib_bs path with
match Build_system.get_artifact_dir path with
| None -> None
| Some lib_bs ->
let compiled_directories =
source_directories |> List.map (Filename.concat lib_bs)
in
let compiled_directories =
match namespace with
| None -> compiled_directories
| Some _ -> lib_bs :: compiled_directories
in
| Some artifact_dir ->
let compiled_directories = [artifact_dir] in
let project_files =
find_project_files ~public:(get_public inner) ~namespace
~path ~source_directories ~lib_bs
~path ~source_directories ~artifact_dir
in
Some (compiled_directories, project_files))
| None -> None
Expand All @@ -334,12 +337,16 @@ let find_dependency_files base config =
Log.log ("Skipping nonexistent dependency: " ^ name);
([], []))
in
match Build_system.get_stdlib base with
| None -> None
| Some stdlib_directory ->
match (Build_system.get_stdlib base, Build_system.get_runtime_dir base) with
| None, _ | _, None -> None
| Some stdlib_directory, Some runtime_dir ->
let compiled_directories, project_files =
let files, directories = List.split dep_files in
(List.concat files, List.concat directories)
in
let all_files = project_files @ collect_files stdlib_directory in
let all_files =
project_files
@ collect_files ~compiled_directory:stdlib_directory
~source_directory:runtime_dir
in
Some (compiled_directories, all_files)
16 changes: 9 additions & 7 deletions analysis/src/packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ let new_bs_package ~root_path =
let rescript_json = Filename.concat root_path "rescript.json" in

let parse_raw raw =
let lib_bs =
let artifact_dir =
match !Cfg.is_doc_gen_from_compiler with
| true -> Build_system.get_stdlib root_path
| false -> Build_system.get_lib_bs root_path
| false -> Build_system.get_artifact_dir root_path
in
match Yojson_helpers.from_string_opt raw with
| Some config -> (
Expand Down Expand Up @@ -82,10 +82,12 @@ let new_bs_package ~root_path =
| _ -> Misc.String_map.empty)
| None -> Misc.String_map.empty
in
match lib_bs with
match artifact_dir with
| None -> None
| Some lib_bs ->
let cached = Cache.read_cache (Cache.target_file_from_lib_bs lib_bs) in
| Some artifact_dir ->
let cached =
Cache.read_cache (Cache.target_file_from_artifact_dir artifact_dir)
in
let project_files, dependencies_files, paths_for_module =
match cached with
| Some cached ->
Expand All @@ -106,7 +108,7 @@ let new_bs_package ~root_path =
let project_files_and_paths =
Find_files.find_project_files
~public:(Find_files.get_public config)
~namespace ~path:root_path ~source_directories ~lib_bs
~namespace ~path:root_path ~source_directories ~artifact_dir
in
let paths_for_module =
make_paths_for_module ~project_files_and_paths
Expand All @@ -125,7 +127,7 @@ let new_bs_package ~root_path =
match namespace with
| None -> []
| Some namespace ->
let cmt = Filename.concat lib_bs namespace ^ ".cmt" in
let cmt = Filename.concat artifact_dir namespace ^ ".cmt" in
Hashtbl.replace paths_for_module namespace (Namespace {cmt});
let path = [Find_files.name_space_to_name namespace] in
[path]
Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"!**/rewatch-ocaml",
"!**/lib/es6",
"!**/lib/js",
"!**/lib/bs",
"!**/lib/rescript",
"!**/playground",
"!**/*.bs.js",
"!**/*.res.js",
Expand Down
1 change: 1 addition & 0 deletions changes/lib-rescript.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Build output moves from `lib/bs` and `lib/ocaml` into one flat `lib/rescript` directory per package, without copies of the sources or the generated JavaScript; the first build removes the old directories, and `lib/rescript` belongs in `.gitignore`. Tools that read `lib/bs/.compiler.log`, `lib/bs/compiler-info.json` or `lib/ocaml` now find these files in `lib/rescript`, and the editor's scratch directory is `lib/rescript/incremental`. The empty `lib/bs/build.ninja` marker is gone; `lib/rescript/.sourcedirs.json` is rewritten when the project graph changes. `@rescript/runtime` ships its sources at the package root.
Loading
Loading