From 8c43d2b48a10f15d6c8ed571e2e98ec0059cf9ff Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sat, 22 Jun 2024 19:57:46 +0200 Subject: [PATCH 1/4] Revert "Remove unused -no-stdlib and use-stdlib (#6778)" This reverts commit 9d19bd9a4f1926934c1a5285d6678d2f2f672218. --- docs/docson/build-schema.json | 4 ++++ jscomp/bsb/bsb_build_schemas.ml | 1 + jscomp/bsb/bsb_config_parse.ml | 10 ++++++++++ jscomp/bsb/bsb_config_types.ml | 1 + jscomp/bsb/bsb_ninja_gen.ml | 3 ++- jscomp/bsb/bsb_ninja_rule.ml | 2 ++ jscomp/bsb/bsb_ninja_rule.mli | 1 + jscomp/bsc/rescript_compiler_main.ml | 3 +++ jscomp/common/js_config.ml | 1 + jscomp/common/js_config.mli | 2 ++ jscomp/others/release.ninja | 2 +- jscomp/runtime/release.ninja | 4 ++-- jscomp/stdlib-406/release.ninja | 2 +- scripts/ninja.js | 4 ++-- 14 files changed, 33 insertions(+), 7 deletions(-) diff --git a/docs/docson/build-schema.json b/docs/docson/build-schema.json index 82d5e24dc0..c0139a7e9f 100644 --- a/docs/docson/build-schema.json +++ b/docs/docson/build-schema.json @@ -472,6 +472,10 @@ "$ref": "#/definitions/package-specs", "description": "ReScript can currently output to [Commonjs](https://en.wikipedia.org/wiki/CommonJS), and [ES6 modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)" }, + "use-stdlib": { + "type": "boolean", + "description": "(Experimental) whether to use the OCaml standard library. Default: true" + }, "external-stdlib": { "type": "string", "description": "Use the external stdlib library instead of the one shipped with the compiler package" diff --git a/jscomp/bsb/bsb_build_schemas.ml b/jscomp/bsb/bsb_build_schemas.ml index 769f6a7a29..5436f1cbb2 100644 --- a/jscomp/bsb/bsb_build_schemas.ml +++ b/jscomp/bsb/bsb_build_schemas.ml @@ -45,6 +45,7 @@ let package_specs = "package-specs" let type_ = "type" let export_all = "all" let export_none = "none" +let use_stdlib = "use-stdlib" let external_stdlib = "external-stdlib" let reason = "reason" let react_jsx = "react-jsx" diff --git a/jscomp/bsb/bsb_config_parse.ml b/jscomp/bsb/bsb_config_parse.ml index 4a9aab131c..747a2b7e08 100644 --- a/jscomp/bsb/bsb_config_parse.ml +++ b/jscomp/bsb/bsb_config_parse.ml @@ -82,6 +82,12 @@ let extract_package_name_and_namespace (map : json_map) : string * string option bsc -runtime runtime_dir@version ``` *) +let check_stdlib (map : json_map) : bool = + (*built_in_package*) + match map.?(Bsb_build_schemas.use_stdlib) with + | Some (False _) -> false + | None | Some _ -> true + let extract_gentype_config (map : json_map) : Bsb_config_types.gentype_config = match map.?(Bsb_build_schemas.gentypeconfig) with | None -> false @@ -260,6 +266,9 @@ let interpret_json (* This line has to be before any calls to Bsb_global_backend.backend, because it'll read the entries array from the bsconfig and set the backend_ref to the first entry, if any. *) + (* The default situation is empty *) + let built_in_package : bool = check_stdlib map in + let pp_flags : string option = extract_string map Bsb_build_schemas.pp_flags (fun p -> if p = "" then @@ -334,6 +343,7 @@ let interpret_json | Pinned_dependency x | Dependency x -> x.package_specs); file_groups = groups; files_to_install = Queue.create (); + built_in_dependency = built_in_package; reason_react_jsx; jsx; generators = extract_generators map; diff --git a/jscomp/bsb/bsb_config_types.ml b/jscomp/bsb/bsb_config_types.ml index c80e3e88bf..db5c007e4d 100644 --- a/jscomp/bsb/bsb_config_types.ml +++ b/jscomp/bsb/bsb_config_types.ml @@ -47,6 +47,7 @@ type t = { bs_dependencies : dependencies; bs_dev_dependencies : dependencies; pinned_dependencies : Set_string.t; + built_in_dependency : bool; warning : Bsb_warning.t; (*TODO: maybe we should always resolve rescript so that we can calculate correct relative path in diff --git a/jscomp/bsb/bsb_ninja_gen.ml b/jscomp/bsb/bsb_ninja_gen.ml index 6c80ffebd4..d10b938591 100644 --- a/jscomp/bsb/bsb_ninja_gen.ml +++ b/jscomp/bsb/bsb_ninja_gen.ml @@ -156,6 +156,7 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind package_specs; file_groups = { files = bs_file_groups }; files_to_install; + built_in_dependency; reason_react_jsx; jsx; uncurried; @@ -204,7 +205,7 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind in let rules : Bsb_ninja_rule.builtin = Bsb_ninja_rule.make_custom_rules ~gentype_config - ~has_postbuild:js_post_build_cmd ~pp_file + ~has_postbuild:js_post_build_cmd ~pp_file ~has_builtin:built_in_dependency ~reason_react_jsx ~jsx ~uncurried ~package_specs ~namespace ~digest ~package_name ~warnings ~ppx_files ~bsc_flags ~dpkg_incls (* dev dependencies *) ~lib_incls (* its own libs *) diff --git a/jscomp/bsb/bsb_ninja_rule.ml b/jscomp/bsb/bsb_ninja_rule.ml index 8904ee0db6..1103a3ac4c 100644 --- a/jscomp/bsb/bsb_ninja_rule.ml +++ b/jscomp/bsb/bsb_ninja_rule.ml @@ -89,6 +89,7 @@ type builtin = { let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config) ~(has_postbuild : string option) ~(pp_file : string option) + ~(has_builtin : bool) ~(reason_react_jsx : Bsb_config_types.reason_react_jsx option) ~(jsx : Bsb_jsx.t) ~(uncurried: bool) ~(digest : string) ~(package_specs : Bsb_package_specs.t) ~(namespace : string option) ~package_name ~warnings @@ -113,6 +114,7 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config) if is_dev then Ext_buffer.add_char_string buf ' ' dev_incls; Ext_buffer.add_char_string buf ' ' lib_incls; if is_dev then Ext_buffer.add_char_string buf ' ' dpkg_incls; + if not has_builtin then Ext_buffer.add_string buf " -nostdlib"; Ext_buffer.add_char_string buf ' ' bsc_flags; Ext_buffer.add_char_string buf ' ' warnings; (* we need "-w a" in the end position to take effect diff --git a/jscomp/bsb/bsb_ninja_rule.mli b/jscomp/bsb/bsb_ninja_rule.mli index e5ede24173..5760ed8940 100644 --- a/jscomp/bsb/bsb_ninja_rule.mli +++ b/jscomp/bsb/bsb_ninja_rule.mli @@ -69,6 +69,7 @@ val make_custom_rules : gentype_config:Bsb_config_types.gentype_config -> has_postbuild:string option -> pp_file:string option -> + has_builtin:bool -> reason_react_jsx:Bsb_config_types.reason_react_jsx option -> jsx:Bsb_jsx.t -> uncurried:bool -> diff --git a/jscomp/bsc/rescript_compiler_main.ml b/jscomp/bsc/rescript_compiler_main.ml index b41f1c7509..bbc97c1452 100644 --- a/jscomp/bsc/rescript_compiler_main.ml +++ b/jscomp/bsc/rescript_compiler_main.ml @@ -352,6 +352,9 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array = "-bs-unsafe-empty-array", set Config.unsafe_empty_array, "*internal* Allow [||] to be polymorphic"; + "-nostdlib", set Js_config.no_stdlib, + "*internal* Don't use stdlib"; + "-color", string_call set_color_option, "*internal* Enable or disable colors in compiler messages\n\ The following settings are supported:\n\ diff --git a/jscomp/common/js_config.ml b/jscomp/common/js_config.ml index 358f0370d5..84f4e22f68 100644 --- a/jscomp/common/js_config.ml +++ b/jscomp/common/js_config.ml @@ -54,6 +54,7 @@ let jsx_module = ref React let jsx_mode = ref Automatic let js_stdout = ref true let all_module_aliases = ref false +let no_stdlib = ref false let no_export = ref false let as_ppx = ref false diff --git a/jscomp/common/js_config.mli b/jscomp/common/js_config.mli index 13048084b2..31855eaca7 100644 --- a/jscomp/common/js_config.mli +++ b/jscomp/common/js_config.mli @@ -87,6 +87,8 @@ val js_stdout : bool ref val all_module_aliases : bool ref +val no_stdlib : bool ref + val no_export : bool ref val as_ppx : bool ref diff --git a/jscomp/others/release.ninja b/jscomp/others/release.ninja index 462cfaaeee..21b03b82eb 100644 --- a/jscomp/others/release.ninja +++ b/jscomp/others/release.ninja @@ -1,5 +1,5 @@ -bsc_primitive_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A +bsc_primitive_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A bsc_flags = $bsc_primitive_flags -open Belt_internals rule cc diff --git a/jscomp/runtime/release.ninja b/jscomp/runtime/release.ninja index d9214de2c3..d21ca55b4d 100644 --- a/jscomp/runtime/release.ninja +++ b/jscomp/runtime/release.ninja @@ -1,5 +1,5 @@ -bsc_no_open_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A +bsc_no_open_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A bsc_flags = $bsc_no_open_flags -open Bs_stdlib_mini rule cc @@ -10,7 +10,7 @@ rule cc_cmi description = $in -> $out o runtime/bs_stdlib_mini.cmi : cc runtime/bs_stdlib_mini.resi - bsc_flags = -nopervasives + bsc_flags = -nostdlib -nopervasives o runtime/js.cmj runtime/js.cmi : cc runtime/js.ml bsc_flags = $bsc_no_open_flags o runtime/caml.cmj : cc_cmi runtime/caml.res | runtime/caml.cmi runtime/caml_int64_extern.cmj diff --git a/jscomp/stdlib-406/release.ninja b/jscomp/stdlib-406/release.ninja index ccd377821a..992f90f652 100644 --- a/jscomp/stdlib-406/release.ninja +++ b/jscomp/stdlib-406/release.ninja @@ -1,5 +1,5 @@ -bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -bs-cross-module-opt -make-runtime -w -9-3-106 -warn-error A -I others +bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -w -9-3-106 -warn-error A -I others rule cc command = $bsc -bs-cmi -bs-cmj $bsc_flags -I stdlib-406 $in diff --git a/scripts/ninja.js b/scripts/ninja.js index 1dda2c3a17..bce31a4465 100755 --- a/scripts/ninja.js +++ b/scripts/ninja.js @@ -30,7 +30,7 @@ var runtimeMliFiles = runtimeFiles.filter( var runtimeSourceFiles = runtimeMlFiles.concat(runtimeMliFiles); var runtimeJsFiles = [...new Set(runtimeSourceFiles.map(baseName))]; -var commonBsFlags = `-no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero `; +var commonBsFlags = `-no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib `; var js_package = pseudoTarget("js_pkg"); var runtimeTarget = pseudoTarget("runtime"); var othersTarget = pseudoTarget("others"); @@ -842,7 +842,7 @@ ${ninjaQuickBuildList([ "bs_stdlib_mini.resi", "cc", ninjaCwd, - [["bsc_flags", "-nopervasives"]], + [["bsc_flags", "-nostdlib -nopervasives"]], [], externalDeps, ], From 3bfb303c534c205555c7a1c246026a66a196c40c Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 23 Jun 2024 10:21:20 +0200 Subject: [PATCH 2/4] Remove use-stdlib option from build schema --- docs/docson/build-schema.json | 4 ---- jscomp/bsb/bsb_build_schemas.ml | 1 - jscomp/bsb/bsb_config_parse.ml | 10 ---------- jscomp/bsb/bsb_config_types.ml | 1 - jscomp/bsb/bsb_ninja_gen.ml | 3 +-- jscomp/bsb/bsb_ninja_rule.ml | 2 -- jscomp/bsb/bsb_ninja_rule.mli | 1 - 7 files changed, 1 insertion(+), 21 deletions(-) diff --git a/docs/docson/build-schema.json b/docs/docson/build-schema.json index c0139a7e9f..82d5e24dc0 100644 --- a/docs/docson/build-schema.json +++ b/docs/docson/build-schema.json @@ -472,10 +472,6 @@ "$ref": "#/definitions/package-specs", "description": "ReScript can currently output to [Commonjs](https://en.wikipedia.org/wiki/CommonJS), and [ES6 modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)" }, - "use-stdlib": { - "type": "boolean", - "description": "(Experimental) whether to use the OCaml standard library. Default: true" - }, "external-stdlib": { "type": "string", "description": "Use the external stdlib library instead of the one shipped with the compiler package" diff --git a/jscomp/bsb/bsb_build_schemas.ml b/jscomp/bsb/bsb_build_schemas.ml index 5436f1cbb2..769f6a7a29 100644 --- a/jscomp/bsb/bsb_build_schemas.ml +++ b/jscomp/bsb/bsb_build_schemas.ml @@ -45,7 +45,6 @@ let package_specs = "package-specs" let type_ = "type" let export_all = "all" let export_none = "none" -let use_stdlib = "use-stdlib" let external_stdlib = "external-stdlib" let reason = "reason" let react_jsx = "react-jsx" diff --git a/jscomp/bsb/bsb_config_parse.ml b/jscomp/bsb/bsb_config_parse.ml index 747a2b7e08..4a9aab131c 100644 --- a/jscomp/bsb/bsb_config_parse.ml +++ b/jscomp/bsb/bsb_config_parse.ml @@ -82,12 +82,6 @@ let extract_package_name_and_namespace (map : json_map) : string * string option bsc -runtime runtime_dir@version ``` *) -let check_stdlib (map : json_map) : bool = - (*built_in_package*) - match map.?(Bsb_build_schemas.use_stdlib) with - | Some (False _) -> false - | None | Some _ -> true - let extract_gentype_config (map : json_map) : Bsb_config_types.gentype_config = match map.?(Bsb_build_schemas.gentypeconfig) with | None -> false @@ -266,9 +260,6 @@ let interpret_json (* This line has to be before any calls to Bsb_global_backend.backend, because it'll read the entries array from the bsconfig and set the backend_ref to the first entry, if any. *) - (* The default situation is empty *) - let built_in_package : bool = check_stdlib map in - let pp_flags : string option = extract_string map Bsb_build_schemas.pp_flags (fun p -> if p = "" then @@ -343,7 +334,6 @@ let interpret_json | Pinned_dependency x | Dependency x -> x.package_specs); file_groups = groups; files_to_install = Queue.create (); - built_in_dependency = built_in_package; reason_react_jsx; jsx; generators = extract_generators map; diff --git a/jscomp/bsb/bsb_config_types.ml b/jscomp/bsb/bsb_config_types.ml index db5c007e4d..c80e3e88bf 100644 --- a/jscomp/bsb/bsb_config_types.ml +++ b/jscomp/bsb/bsb_config_types.ml @@ -47,7 +47,6 @@ type t = { bs_dependencies : dependencies; bs_dev_dependencies : dependencies; pinned_dependencies : Set_string.t; - built_in_dependency : bool; warning : Bsb_warning.t; (*TODO: maybe we should always resolve rescript so that we can calculate correct relative path in diff --git a/jscomp/bsb/bsb_ninja_gen.ml b/jscomp/bsb/bsb_ninja_gen.ml index d10b938591..6c80ffebd4 100644 --- a/jscomp/bsb/bsb_ninja_gen.ml +++ b/jscomp/bsb/bsb_ninja_gen.ml @@ -156,7 +156,6 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind package_specs; file_groups = { files = bs_file_groups }; files_to_install; - built_in_dependency; reason_react_jsx; jsx; uncurried; @@ -205,7 +204,7 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind in let rules : Bsb_ninja_rule.builtin = Bsb_ninja_rule.make_custom_rules ~gentype_config - ~has_postbuild:js_post_build_cmd ~pp_file ~has_builtin:built_in_dependency + ~has_postbuild:js_post_build_cmd ~pp_file ~reason_react_jsx ~jsx ~uncurried ~package_specs ~namespace ~digest ~package_name ~warnings ~ppx_files ~bsc_flags ~dpkg_incls (* dev dependencies *) ~lib_incls (* its own libs *) diff --git a/jscomp/bsb/bsb_ninja_rule.ml b/jscomp/bsb/bsb_ninja_rule.ml index 1103a3ac4c..8904ee0db6 100644 --- a/jscomp/bsb/bsb_ninja_rule.ml +++ b/jscomp/bsb/bsb_ninja_rule.ml @@ -89,7 +89,6 @@ type builtin = { let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config) ~(has_postbuild : string option) ~(pp_file : string option) - ~(has_builtin : bool) ~(reason_react_jsx : Bsb_config_types.reason_react_jsx option) ~(jsx : Bsb_jsx.t) ~(uncurried: bool) ~(digest : string) ~(package_specs : Bsb_package_specs.t) ~(namespace : string option) ~package_name ~warnings @@ -114,7 +113,6 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config) if is_dev then Ext_buffer.add_char_string buf ' ' dev_incls; Ext_buffer.add_char_string buf ' ' lib_incls; if is_dev then Ext_buffer.add_char_string buf ' ' dpkg_incls; - if not has_builtin then Ext_buffer.add_string buf " -nostdlib"; Ext_buffer.add_char_string buf ' ' bsc_flags; Ext_buffer.add_char_string buf ' ' warnings; (* we need "-w a" in the end position to take effect diff --git a/jscomp/bsb/bsb_ninja_rule.mli b/jscomp/bsb/bsb_ninja_rule.mli index 5760ed8940..e5ede24173 100644 --- a/jscomp/bsb/bsb_ninja_rule.mli +++ b/jscomp/bsb/bsb_ninja_rule.mli @@ -69,7 +69,6 @@ val make_custom_rules : gentype_config:Bsb_config_types.gentype_config -> has_postbuild:string option -> pp_file:string option -> - has_builtin:bool -> reason_react_jsx:Bsb_config_types.reason_react_jsx option -> jsx:Bsb_jsx.t -> uncurried:bool -> From bb8320ea823c0afdeba82fa4e64c31009dd8ddf0 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sat, 22 Jun 2024 20:40:01 +0200 Subject: [PATCH 3/4] Omit standard library dir from load path if -nostdlib is set --- jscomp/core/res_compmisc.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jscomp/core/res_compmisc.ml b/jscomp/core/res_compmisc.ml index 1c7f3974e3..6213e2e022 100644 --- a/jscomp/core/res_compmisc.ml +++ b/jscomp/core/res_compmisc.ml @@ -27,7 +27,9 @@ let init_path () = let exp_dirs = List.map (Misc.expand_directory Config.standard_library) dirs in - Config.load_path := List.rev_append exp_dirs [Config.standard_library]; + Config.load_path := + if !Js_config.no_stdlib then exp_dirs + else (List.rev_append exp_dirs [Config.standard_library]); Env.reset_cache () (* Return the initial environment in which compilation proceeds. *) From 1d08b92f84b01c7150c3d85efbb3c3e887cb1147 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sat, 22 Jun 2024 20:40:01 +0200 Subject: [PATCH 4/4] CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5fbc7d096..ffaa65be62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ - Convert OCaml codebase to snake case style. https://github.com/rescript-lang/rescript-compiler/pull/6702 - Fix location of let bindings with attributes. https://github.com/rescript-lang/rescript-compiler/pull/6791 - Refactor uppercase exotic ident handling. https://github.com/rescript-lang/rescript-compiler/pull/6779 +- Fix `-nostdlib` internal compiler option. https://github.com/rescript-lang/rescript-compiler/pull/6824 #### :nail_care: Polish @@ -60,7 +61,7 @@ - In generated code, use `let` instead of `var`. https://github.com/rescript-lang/rescript-compiler/pull/6102 - Turn off transformation for closures inside loops when capturing loop variables, now that `let` is emitted instead of `var`. https://github.com/rescript-lang/rescript-compiler/pull/6480 - Improve unused attribute warning message. https://github.com/rescript-lang/rescript-compiler/pull/6787 -- Remove unused -no-stdlib compiler option. https://github.com/rescript-lang/rescript-compiler/pull/6778 +- Remove internal option `use-stdlib` from build schema. https://github.com/rescript-lang/rescript-compiler/pull/6778 # 11.1.1