This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,13 @@
(library
(name impl_intf_only)
(modules :standard \ run)
(implements vlib.intfonly))
(executable
(name run)
(libraries impl_intf_only)
(modules run))
(alias
(name default)
(action (run ./run.exe)))

View file

@ -0,0 +1,2 @@
let () =
Printf.printf "magic number: %d\n" (Vlib_intfonly.implme ())

View file

@ -0,0 +1,5 @@
module X : Foo.S = struct
let mli_only = print_endline
end
let implme () = X.mli_only "implemented mli only"; 42

View file

@ -0,0 +1,13 @@
(library
(name impl_native_only)
(modules :standard \ run)
(implements vlib.nativeonly))
(executable
(name run)
(libraries impl_native_only)
(modules run))
(alias
(name default)
(action (run ./run.exe)))

View file

@ -0,0 +1,2 @@
let () =
Vlib_native_only.run_native ()

View file

@ -0,0 +1,13 @@
(library
(name impl_privatemodule)
(modules :standard \ run)
(implements vlib.privatemodule))
(executable
(name run)
(libraries impl_privatemodule)
(modules run))
(alias
(name default)
(action (run ./run.exe)))

View file

@ -0,0 +1,7 @@
(executable
(name test)
(libraries impl))
(alias
(name default)
(action (run ./test.exe)))

View file

@ -0,0 +1,3 @@
(lang dune 1.7)
(package (name dune-vlib))

View file

@ -0,0 +1,4 @@
(library
(name impl)
(public_name dune-vlib.impl)
(implements vlib))

View file

@ -0,0 +1,3 @@
let run () =
Bar.bar ();
print_endline "Foo.run implemented"

View file

@ -0,0 +1,55 @@
Test that we can implement external libraries.
First we create an external library
$ dune build --root vlib @install
Entering directory 'vlib'
Leaving directory 'vlib'
Then we make sure that we can implement it
$ env OCAMLPATH=vlib/_build/install/default/lib dune build @default @install --root impl
Entering directory 'impl'
bar from vlib
Foo.run implemented
Leaving directory 'impl'
Make sure that we can also implement native only variants
$ env OCAMLPATH=vlib/_build/install/default/lib dune build --root impl-native-only --debug-dependency-path
Entering directory 'impl-native-only'
implement virtual module
Leaving directory 'impl-native-only'
We can implement external variants with mli only modules
$ env OCAMLPATH=vlib/_build/install/default/lib dune build --root impl-intf-only --debug-dependency-path
Entering directory 'impl-intf-only'
implemented mli only
magic number: 42
Leaving directory 'impl-intf-only'
Implement external virtual libraries with private modules
$ env OCAMLPATH=vlib/_build/install/default/lib dune build --root impl-private-module --debug-dependency-path
Entering directory 'impl-private-module'
Name: implement virtual module. Magic number: 42
Leaving directory 'impl-private-module'
Now we test the following use case:
- A virtual library and its implementation are installed
- We are able to use the implementation as an external dependency in a project
Currently, dune's behavior is broken in this situation. The virtual library's
modules remain hidden.
$ export OCAMLPATH=$PWD/vlib/_build/install/default/lib:$PWD/impl/_build/install/default/lib
$ mkdir use-external-impl && cd use-external-impl
$ cat >dune-project <<EOF
> (lang dune 3.0)
> EOF
$ cat >dune <<EOF
> (executable
> (name blah)
> (libraries dune-vlib.impl))
> EOF
$ cat >blah.ml <<EOF
> Vlib.Foo.run ()
> EOF
$ dune exec ./blah.exe
bar from vlib
Foo.run implemented
$ cd ..

View file

@ -0,0 +1 @@
let bar () = print_endline "bar from vlib"

View file

@ -0,0 +1,3 @@
(library
(public_name vlib)
(virtual_modules foo))

View file

@ -0,0 +1,5 @@
(library
(name vlib_intfonly)
(public_name vlib.intfonly)
(modules_without_implementation foo)
(virtual_modules vlib_intfonly))

View file

@ -0,0 +1,3 @@
module type S = sig
val mli_only : string -> unit
end

View file

@ -0,0 +1,5 @@
(library
(name vlib_native_only)
(public_name vlib.nativeonly)
(virtual_modules virt_module)
(modes native))

View file

@ -0,0 +1,2 @@
let run_native () =
print_endline Virt_module.v

View file

@ -0,0 +1,5 @@
(library
(name vlib_privatemodule)
(public_name vlib.privatemodule)
(virtual_modules virt_module)
(private_modules privatemodule))

View file

@ -0,0 +1,3 @@
let run () =
Printf.printf "Name: %s. Magic number: %d\n"
Virt_module.name Privatemodule.number