Skip to content
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

bc-for-jsoo: use -noautolink, do not depend on stublibs #7156

Merged
merged 6 commits into from
Feb 23, 2023
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: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Unreleased
- Allow the main module of a library with `(stdlib ...)` to depend on other
libraries (#7154, @anmonteiro).

- Bytecode executables built for JSOO are linked with `-noautolink` and no
longer depend on the shared stubs of their dependent libraries (#7156, @nojb)

3.7.0 (2023-02-17)
------------------

Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/exe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Linkage = struct
let byte_for_jsoo =
{ mode = Byte_for_jsoo
; ext = ".bc-for-jsoo"
; flags = [ "-no-check-prims" ]
; flags = [ "-no-check-prims"; "-noautolink" ]
}

let native = { mode = Native; ext = ".exe"; flags = [] }
Expand Down
6 changes: 4 additions & 2 deletions src/dune_rules/lib_flags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module Link_params = struct
let select_lib_files = Mode.Map.Multi.for_only ~and_all:true lib_files in
let+ hidden_deps =
match mode with
| Byte | Byte_for_jsoo -> Memo.return dll_files
| Byte -> Memo.return dll_files
| Byte_for_jsoo -> Memo.return []
| Byte_with_stubs_statically_linked_in ->
Memo.return @@ select_lib_files Mode.Byte
| Native ->
Expand All @@ -39,7 +40,8 @@ module Link_params = struct
let include_dirs =
let files =
match mode with
| Byte | Byte_for_jsoo -> dll_files
| Byte -> dll_files
| Byte_for_jsoo -> []
| Byte_with_stubs_statically_linked_in | Native ->
select_lib_files Mode.Native
in
Expand Down
52 changes: 52 additions & 0 deletions test/blackbox-tests/test-cases/jsoo/jsoo-noautolink.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
We check that .bc-for-jsoo targets are built with -noautolink and do not depend
on the shared stubs of dependent libraries.

$ cat >dune-project <<EOF
> (lang dune 3.7)
> EOF

$ cat >dune <<EOF
> (library
> (name libA)
> (modules libA)
> (foreign_stubs
> (language c)
> (names stubsA)))
> (executable
> (name mainA)
> (libraries libA)
> (modules mainA)
> (modes js))
> EOF
$ touch stubsA.c mainA.ml libA.ml

$ dune build --display verbose --profile release mainA.bc.js 2>&1 | sed -n 's#.*\(-o mainA.bc-for-jsoo .*\)#\1#p'
-o mainA.bc-for-jsoo -no-check-prims -noautolink libA.cma .mainA.eobjs/byte/dune__exe__MainA.cmo)

The file dlllibA_stubs.so should not appear in the next list.

$ find _build/default | sort
_build/default
_build/default/.dune
_build/default/.dune/configurator
_build/default/.dune/configurator.v2
_build/default/.libA.objs
_build/default/.libA.objs/byte
_build/default/.libA.objs/byte/libA.cmi
_build/default/.libA.objs/byte/libA.cmo
_build/default/.libA.objs/byte/libA.cmt
_build/default/.mainA.eobjs
_build/default/.mainA.eobjs/byte
_build/default/.mainA.eobjs/byte/dune__exe__MainA.cmi
_build/default/.mainA.eobjs/byte/dune__exe__MainA.cmo
_build/default/.mainA.eobjs/byte/dune__exe__MainA.cmt
_build/default/.mainA.eobjs/byte/dune__exe__MainA.cmti
_build/default/.merlin-conf
_build/default/.merlin-conf/exe-mainA
_build/default/.merlin-conf/lib-libA
_build/default/libA.cma
_build/default/libA.ml
_build/default/mainA.bc-for-jsoo
_build/default/mainA.bc.js
_build/default/mainA.ml
_build/default/mainA.mli
19 changes: 3 additions & 16 deletions test/blackbox-tests/test-cases/jsoo/simple.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,11 @@ Compilation using jsoo with disable_dynamically_linked_foreign_archives = true
$ dune clean
$ dune build bin/technologic.bc.js @install --profile dev

Js_of_ocaml whole program compilation doesn't work with
disable_dynamically_linked_foreign_archives = true
We would like the following to succeed:
Js_of_ocaml whole program compilation works with
disable_dynamically_linked_foreign_archives = true:

$ dune build bin/technologic.bc.js @install --profile release
File "bin/dune", line 2, characters 8-19:
2 | (names technologic)
^^^^^^^^^^^
Error: No rule found for lib/dllx_stubs.so
[1]

Js_of_ocaml whole program compilation doesn't work with
disable_dynamically_linked_foreign_archives = true
We expect a runtime error when running this bc-for-jsoo file.

$ dune exe bin/technologic.bc-for-jsoo
File "bin/dune", line 2, characters 8-19:
2 | (names technologic)
^^^^^^^^^^^
Error: No rule found for lib/dllx_stubs.so
[1]
$ ! dune exe bin/technologic.bc-for-jsoo >/dev/null 2>&1