Skip to content

Allow user to choose a light-weight runtime (part 1) #4920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2021
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
3 changes: 2 additions & 1 deletion jscomp/bsb/bsb_config_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

(* let get_list_string = Bsb_build_util.get_list_string *)
let (//) = Ext_path.combine
let current_package : Bsb_pkg_types.t = Global Bs_version.package_name

let resolve_package cwd package_name =
let x = Bsb_pkg.resolve_bs_package ~cwd package_name in
{
Expand Down Expand Up @@ -113,6 +113,7 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) =
| None
| Some _ ->
begin
let current_package : Bsb_pkg_types.t = Global !Bs_version.package_name in
if Sys.getenv_opt "RES_SKIP_STDLIB_CHECK" = None then begin
let stdlib_path =
Bsb_pkg.resolve_bs_package ~cwd current_package in
Expand Down
6 changes: 3 additions & 3 deletions jscomp/bsb/bsb_exception.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ let print (fmt : Format.formatter) (x : error) =
| None -> Ext_string.empty
| Some x -> " in " ^ x in
let name = Bsb_pkg_types.to_string name in
if Ext_string.equal name Bs_version.package_name then
if Ext_string.equal name !Bs_version.package_name then
Format.fprintf fmt
"File \"bsconfig.json\", line 1\n\
@{<error>Error:@} package @{<error>bs-platform@} is not found %s\n\
@{<error>Error:@} package @{<error>%s@} is not found %s\n\
It's the basic, required package. If you have it installed globally,\n\
Please run `npm link bs-platform` to make it available" in_json
Please run `npm link bs-platform` to make it available" name in_json
else
Format.fprintf fmt
"File \"bsconfig.json\", line 1\n\
Expand Down
2 changes: 1 addition & 1 deletion jscomp/build_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fs.writeFileSync(
let version = "${version}"
let header =
"// Generated by ReScript, PLEASE EDIT WITH CARE"
let package_name = "${name}"
let package_name = ref "${name}"
`,
"utf8"
);
4 changes: 2 additions & 2 deletions jscomp/common/bs_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
let version = "8.4.0"
let version = "8.5.0"
let header =
"// Generated by ReScript, PLEASE EDIT WITH CARE"
let package_name = "bs-platform"
let package_name = ref "bs-platform"

2 changes: 1 addition & 1 deletion jscomp/common/bs_version.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ val version : string

val header : string

val package_name : string
val package_name : string ref
1 change: 1 addition & 0 deletions jscomp/core/js_name_of_module_id.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let fix_path_for_windows : string -> string =
else fun s -> s


(* dependency is runtime module *)
let get_runtime_module_path
(dep_module_id : Lam_module_ident.t)
(current_package_info : Js_packages_info.t)
Expand Down
33 changes: 18 additions & 15 deletions jscomp/core/js_packages_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type package_name =



let runtime_package_name = "bs-platform"



let (//) = Filename.concat
Expand All @@ -70,7 +70,7 @@ let runtime_dir_of_module_system (ms : module_system ) =
let runtime_package_path
(ms : module_system)
js_file =
runtime_package_name // "lib" // runtime_dir_of_module_system ms // js_file
!Bs_version.package_name // "lib" // runtime_dir_of_module_system ms // js_file


type t =
Expand All @@ -86,6 +86,14 @@ let runtime_package_specs : t = {
{module_system = NodeJS; path = "lib/js"; suffix = Js};
]
}

(**
populated by the command line
*)
let runtime_test_package_specs : t = {
name = Pkg_runtime;
module_systems = []
}
let same_package_by_name (x : t) (y : t) = x.name = y.name

let is_runtime_package (x : t) =
Expand All @@ -112,16 +120,10 @@ let empty : t =
module_systems = []
}

let from_name (name : string) =
if name = runtime_package_name then
{
name = Pkg_runtime ; module_systems = []
}
else
{
name = Pkg_normal name ;
module_systems = []
}
let from_name (name : string) : t = {
name = Pkg_normal name ;
module_systems = []
}

let is_empty (x : t) =
x.name = Pkg_empty
Expand Down Expand Up @@ -156,7 +158,7 @@ let dump_package_name fmt (x : package_name) =
match x with
| Pkg_empty -> Format.fprintf fmt "@empty_pkg@"
| Pkg_normal s -> Format.pp_print_string fmt s
| Pkg_runtime -> Format.pp_print_string fmt runtime_package_name
| Pkg_runtime -> Format.pp_print_string fmt "@runtime"

let dump_packages_info
(fmt : Format.formatter)
Expand Down Expand Up @@ -208,7 +210,7 @@ let query_package_infos
compatible k.module_system module_system) with
| Some k ->
let rel_path = k.path in
let pkg_rel_path = runtime_package_name // rel_path in
let pkg_rel_path = !Bs_version.package_name // rel_path in
Package_found
{
rel_path ;
Expand All @@ -221,7 +223,8 @@ let query_package_infos

let get_js_path
(x : t )
module_system
(module_system : module_system)
: string
=
match Ext_list.find_first x.module_systems (fun k ->
compatible k.module_system module_system) with
Expand Down
3 changes: 3 additions & 0 deletions jscomp/core/js_packages_info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type package_info = {
type t

val runtime_package_specs : t

val runtime_test_package_specs : t

val is_runtime_package:
t ->
bool
Expand Down
5 changes: 5 additions & 0 deletions jscomp/core/js_packages_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ let set_package_name name =
else
Bsc_args.bad_arg "duplicated flag for -bs-package-name"

let make_runtime () : unit =
packages_info := Js_packages_info.runtime_package_specs

let make_runtime_test () : unit =
packages_info := Js_packages_info.runtime_test_package_specs
let set_package_map module_name =
(* set_package_name name ;
let module_name = Ext_namespace.namespace_of_package_name name in *)
Expand Down
5 changes: 5 additions & 0 deletions jscomp/core/js_packages_state.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

val set_package_name : string -> unit

val make_runtime:
unit -> unit

val make_runtime_test:
unit -> unit
val set_package_map : string -> unit

val get_packages_info :
Expand Down
6 changes: 5 additions & 1 deletion jscomp/main/js_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,11 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
"<list> Enable or disable error status for warnings according\n\
to <list>. See option -w for the syntax of <list>.\n\
Default setting is " ^ Bsc_warnings.defaults_warn_error;

"-make-runtime", unit_call Js_packages_state.make_runtime,
"*internal* make runtime library";
"-make-runtime-test", unit_call Js_packages_state.make_runtime_test,
"*internal* make runtime test library";

|]


Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/release.ninja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6:.mjs -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime
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 -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime

rule cc
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I others $in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/runtime/release.ninja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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 -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6:.mjs -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
Expand Down
2 changes: 1 addition & 1 deletion jscomp/stdlib-406/release.ninja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6:.mjs -w -9-3-106 -warn-error A -I runtime -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 runtime -I others

rule cc
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I stdlib-406 $in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/build.ninja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

bsc_flags = -bs-no-version-header -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I $stdlib -I others
bsc_flags = -bs-no-version-header -bs-cross-module-opt -make-runtime-test -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I $stdlib -I others

rule cc
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I test $in
Expand Down
15 changes: 8 additions & 7 deletions lib/4.06.1/bsb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ val version : string

val header : string

val package_name : string
val package_name : string ref
end = struct
#1 "bs_version.ml"

Expand All @@ -55,10 +55,10 @@ end = struct
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
let version = "8.4.0"
let version = "8.5.0"
let header =
"// Generated by ReScript, PLEASE EDIT WITH CARE"
let package_name = "bs-platform"
let package_name = ref "bs-platform"

end
module Ext_array : sig
Expand Down Expand Up @@ -6500,12 +6500,12 @@ let print (fmt : Format.formatter) (x : error) =
| None -> Ext_string.empty
| Some x -> " in " ^ x in
let name = Bsb_pkg_types.to_string name in
if Ext_string.equal name Bs_version.package_name then
if Ext_string.equal name !Bs_version.package_name then
Format.fprintf fmt
"File \"bsconfig.json\", line 1\n\
@{<error>Error:@} package @{<error>bs-platform@} is not found %s\n\
@{<error>Error:@} package @{<error>%s@} is not found %s\n\
It's the basic, required package. If you have it installed globally,\n\
Please run `npm link bs-platform` to make it available" in_json
Please run `npm link bs-platform` to make it available" name in_json
else
Format.fprintf fmt
"File \"bsconfig.json\", line 1\n\
Expand Down Expand Up @@ -11054,7 +11054,7 @@ end = struct

(* let get_list_string = Bsb_build_util.get_list_string *)
let (//) = Ext_path.combine
let current_package : Bsb_pkg_types.t = Global Bs_version.package_name

let resolve_package cwd package_name =
let x = Bsb_pkg.resolve_bs_package ~cwd package_name in
{
Expand Down Expand Up @@ -11142,6 +11142,7 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) =
| None
| Some _ ->
begin
let current_package : Bsb_pkg_types.t = Global !Bs_version.package_name in
if Sys.getenv_opt "RES_SKIP_STDLIB_CHECK" = None then begin
let stdlib_path =
Bsb_pkg.resolve_bs_package ~cwd current_package in
Expand Down
Loading