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,5 @@
(executable
(name p)
(public_name p))
(rule (with-stdout-to file (run ./p.exe)))

View file

@ -0,0 +1,11 @@
(lang dune 1.10)
(context (default))
(context (default
(name cross-1)
(host default)))
(context (default
(name cross-2)
(host cross-1)))

View file

@ -0,0 +1 @@
let () = Printf.printf "%d\n" 137

View file

@ -0,0 +1,8 @@
$ dune build file @install
File "dune-workspace", lines 5-7, characters 9-50:
5 | (context (default
6 | (name cross-1)
7 | (host default)))
Error: Context 'cross-1' is both a host (for 'cross-2') and a target (for
'default').
[1]

View file

@ -0,0 +1,5 @@
(executable
(name p)
(public_name p))
(rule (with-stdout-to file (run ./p.exe)))

View file

@ -0,0 +1,7 @@
(lang dune 1.10)
(context (default))
(context (default
(name cross-1)
(host oups)))

View file

@ -0,0 +1 @@
let () = Printf.printf "%d\n" 137

View file

@ -0,0 +1,7 @@
$ dune build file @install
File "dune-workspace", lines 5-7, characters 9-47:
5 | (context (default
6 | (name cross-1)
7 | (host oups)))
Error: Undefined host context 'oups' for 'cross-1'.
[1]

View file

@ -0,0 +1,4 @@
(library
(name repro)
(public_name repro)
(modules foo))

View file

@ -0,0 +1,23 @@
Installing a library with `-x foo` should install the library for that context
$ mkdir prefix
$ export OCAMLFIND_CONF=$PWD/etc/findlib.conf
$ dune build @install -x foo
$ dune install --dry-run --prefix prefix --display short -p repro -x foo 2>&1 | grep "Installing"
Installing prefix/foo-sysroot/lib/repro/META
Installing prefix/foo-sysroot/lib/repro/dune-package
Installing prefix/foo-sysroot/lib/repro/foo.ml
Installing prefix/foo-sysroot/lib/repro/repro.a
Installing prefix/foo-sysroot/lib/repro/repro.cma
Installing prefix/foo-sysroot/lib/repro/repro.cmi
Installing prefix/foo-sysroot/lib/repro/repro.cmt
Installing prefix/foo-sysroot/lib/repro/repro.cmx
Installing prefix/foo-sysroot/lib/repro/repro.cmxa
Installing prefix/foo-sysroot/lib/repro/repro.ml
Installing prefix/foo-sysroot/lib/repro/repro__Foo.cmi
Installing prefix/foo-sysroot/lib/repro/repro__Foo.cmt
Installing prefix/foo-sysroot/lib/repro/repro__Foo.cmx
Installing prefix/foo-sysroot/lib/repro/repro.cmxs

View file

@ -0,0 +1,97 @@
In a cross-compilation scenario, Dune should be able to find libraries defined
in the default findlib.conf
$ mkdir -p etc/findlib.conf.d
$ export OCAMLFIND_CONF=$PWD/etc/findlib.conf
$ cat >etc/findlib.conf <<EOF
> path="$PWD/prefix/lib"
> ocamldep="$PWD/notocamldep"
> EOF
$ cat >etc/findlib.conf.d/foo.conf <<EOF
> path(foo)=""
> ocamldep(foo)="$PWD/notocamldep-foo"
> EOF
$ cat >notocamldep <<EOF
> #!/usr/bin/env sh
> ocamldep "\$@"
> EOF
$ cat >notocamldep-foo <<EOF
> #!/usr/bin/env sh
> ocamldep "\$@"
> EOF
$ chmod +x notocamldep notocamldep-foo
$ mkdir lib
$ cat > lib/dune-project <<EOF
> (lang dune 3.7)
> (package (name libdep))
> EOF
$ cat > lib/dune <<EOF
> (library (public_name libdep))
> EOF
$ cat > lib/libdep.ml <<EOF
> let x = 1
> EOF
$ dune build --root lib @install
Entering directory 'lib'
Leaving directory 'lib'
$ dune install --root lib --prefix $PWD/prefix
$ mkdir app
$ cat > app/dune-project <<EOF
> (lang dune 3.7)
> (package (name repro))
> EOF
$ cat > app/dune <<EOF
> (executable
> (name gen)
> (modules gen)
> (enabled_if
> (= %{context_name} "default"))
> (libraries libdep))
> (rule
> (with-stdout-to
> gen.ml
> (echo "let () = Format.printf \"let x = 1\"")))
> (library
> (name repro)
> (public_name repro)
> (modules foo))
> (rule
> (with-stdout-to
> foo.ml
> (run ./gen.exe)))
> EOF
ocamlfind can find it
$ ocamlfind list | grep libdep
libdep (version: n/a)
Dune should be able to find it too
$ dune build --root=app @install -x foo --verbose 2>&1 | grep notocamldep-foo
Running[8]: (cd _build/default.foo && $TESTCASE_ROOT/notocamldep-foo -modules -impl foo.ml) > _build/default.foo/.repro.objs/repro__Foo.impl.d
Library is built in the target context
$ ls app/_build/default.foo
META.repro
foo.ml
repro-foo.install
repro.a
repro.cma
repro.cmxa
repro.cmxs
repro.dune-package
repro.ml-gen
Executable was built in the host context
$ ls app/_build/default
gen.exe
gen.ml
gen.mli

View file

@ -0,0 +1,4 @@
(executable
(name blah)
(public_name blah)
(libraries p))

View file

@ -0,0 +1 @@
(rule (with-stdout-to file (run ./bin/blah.exe)))

View file

@ -0,0 +1,3 @@
(library
(name p)
(public_name p))

View file

@ -0,0 +1,42 @@
$ env OCAMLFIND_CONF=$PWD/etc/findlib.conf dune build --display short -x foo file @install --promote-install-files
ocamldep bin/.blah.eobjs/blah.impl.d
ocamlc lib/.p.objs/byte/p.{cmi,cmo,cmt}
ocamldep bin/.blah.eobjs/blah.impl.d [default.foo]
ocamlc lib/.p.objs/byte/p.{cmi,cmo,cmt} [default.foo]
ocamlopt lib/.p.objs/native/p.{cmx,o}
ocamlc bin/.blah.eobjs/byte/blah.{cmi,cmo,cmt}
ocamlopt lib/.p.objs/native/p.{cmx,o} [default.foo]
ocamlc lib/p.cma [default.foo]
ocamlc bin/.blah.eobjs/byte/blah.{cmi,cmo,cmt} [default.foo]
ocamlopt lib/p.{a,cmxa}
ocamlopt bin/.blah.eobjs/native/blah.{cmx,o}
ocamlopt lib/p.{a,cmxa} [default.foo]
ocamlopt bin/.blah.eobjs/native/blah.{cmx,o} [default.foo]
ocamlopt bin/blah.exe
ocamlopt lib/p.cmxs [default.foo]
ocamlopt bin/blah.exe [default.foo]
blah file
blah file [default.foo]
$ cat _build/default.foo/file
42
$ ls *.install
p-foo.install
$ dune_cmd cat p-foo.install | dune_cmd sanitize
lib: [
"_build/install/default.foo/lib/p/META" {"../../foo-sysroot/lib/p/META"}
"_build/install/default.foo/lib/p/dune-package" {"../../foo-sysroot/lib/p/dune-package"}
"_build/install/default.foo/lib/p/opam" {"../../foo-sysroot/lib/p/opam"}
"_build/install/default.foo/lib/p/p$ext_lib" {"../../foo-sysroot/lib/p/p$ext_lib"}
"_build/install/default.foo/lib/p/p.cma" {"../../foo-sysroot/lib/p/p.cma"}
"_build/install/default.foo/lib/p/p.cmi" {"../../foo-sysroot/lib/p/p.cmi"}
"_build/install/default.foo/lib/p/p.cmt" {"../../foo-sysroot/lib/p/p.cmt"}
"_build/install/default.foo/lib/p/p.cmx" {"../../foo-sysroot/lib/p/p.cmx"}
"_build/install/default.foo/lib/p/p.cmxa" {"../../foo-sysroot/lib/p/p.cmxa"}
"_build/install/default.foo/lib/p/p.ml" {"../../foo-sysroot/lib/p/p.ml"}
]
libexec: [
"_build/install/default.foo/lib/p/p.cmxs" {"../../foo-sysroot/lib/p/p.cmxs"}
]
bin: [
"_build/install/default.foo/bin/blah" {"../foo-sysroot/bin/blah"}
]

View file

@ -0,0 +1,29 @@
Reproduce #6843
Cross compilation setup that causes dune to crash
$ cat >dune-workspace <<EOF
> (lang dune 3.6)
> (context (default))
> (context
> (default
> (name esperanto)
> (host default)))
> EOF
$ cat >dune-project <<EOF
> (lang dune 3.6)
> EOF
$ cat >dune <<EOF
> (executable (name cat))
> EOF
$ export OCAMLFIND_CONF=$PWD/etc/findlib.conf
$ mkdir -p etc/findlib.conf.d
$ touch etc/findlib.conf etc/findlib.conf.d/esperanto.conf
$ dune build -x esperanto ./cat.exe
File "dune", line 1, characters 18-21:
1 | (executable (name cat))
^^^
Error: Module "Cat" doesn't exist.
[1]

View file

@ -0,0 +1,43 @@
Dune shows an error message when ocamlfind isn't in PATH and OCAMLFIND_CONF
isn't set
$ cat > dune-project <<EOF
> (lang dune 3.7)
> (package (name repro))
> EOF
$ cat > dune <<EOF
> (executable
> (name gen)
> (modules gen)
> (enabled_if
> (= %{context_name} "default"))
> (libraries libdep))
> (rule
> (with-stdout-to
> gen.ml
> (echo "let () = Format.printf \"let x = 1\"")))
> (library
> (name repro)
> (public_name repro)
> (modules))
> EOF
$ mkdir ocaml-bin
$ cat > ocaml-bin/ocamlc <<EOF
> #!/usr/bin/env sh
> export PATH="\$ORIG_PATH"
> exec ocamlc "\$@"
> EOF
$ chmod +x ocaml-bin/ocamlc
$ DUNE_PATH=$(dirname `which dune`)
$ SH_PATH=$(dirname `which sh`)
$ env ORIG_PATH="$PATH" PATH="$SH_PATH:$DUNE_PATH:$PWD/ocaml-bin" dune build @install -x foo
Error: Could not find `ocamlfind' in PATH or an environment variable
`OCAMLFIND_CONF' while cross-compiling with toolchain `foo'
Hint:
- `opam install ocamlfind' and/or:
- Point `OCAMLFIND_CONF' to the findlib configuration that defines this
toolchain
[1]

View file

@ -0,0 +1,5 @@
(executable
(name p)
(public_name p))
(rule (with-stdout-to file (run ./p.exe)))

View file

@ -0,0 +1,7 @@
(lang dune 1.10)
(context (default))
(context (default
(name cross)
(host default)))

View file

@ -0,0 +1 @@
let () = Printf.printf "%d\n" 137

View file

@ -0,0 +1,14 @@
$ dune build --display short file @install
ocamldep .p.eobjs/p.impl.d
ocamldep .p.eobjs/p.impl.d [cross]
ocamlc .p.eobjs/byte/p.{cmi,cmo,cmt}
ocamlc .p.eobjs/byte/p.{cmi,cmo,cmt} [cross]
ocamlopt .p.eobjs/native/p.{cmx,o}
ocamlopt .p.eobjs/native/p.{cmx,o} [cross]
ocamlopt p.exe
ocamlopt p.exe [cross]
p file
p file [cross]
$ cat _build/cross/file
137

View file

@ -0,0 +1,7 @@
(lang dune 2.0)
(context (default))
(context (default
(name cross-environment)
(host default)))

View file

@ -0,0 +1,3 @@
(library
(name foolib)
(preprocess (pps fooppx)))

View file

@ -0,0 +1,5 @@
(library
(name fooppx)
(enabled_if (= %{context_name} "default"))
(kind ppx_rewriter)
(libraries ppxlib))

View file

@ -0,0 +1,12 @@
# Using a ppx in a cross-compiled build context makes dune try to build the ppx
# in the target context instead of the host, then fail.
$ dune build --debug-dependency-path
File "lib/dune", line 3, characters 18-24:
3 | (preprocess (pps fooppx)))
^^^^^^
Error: Library "fooppx" in _build/cross-environment/ppx is hidden
(unsatisfied 'enabled_if').
-> required by _build/cross-environment/lib/lib.pp.ml
-> required by alias lib/all (context cross-environment)
-> required by alias default (context cross-environment)
[1]

View file

@ -0,0 +1,7 @@
(library
(name other_ppx_eq)
(public_name other-ppx.eq)
(libraries other-ppx.api)
(ppx.driver
(main Other_ppx_eq.main))
(kind ppx_deriver))

View file

@ -0,0 +1,15 @@
let deriver = "eq"
let main () =
let out = ref "" in
let args =
[ ("-o", Arg.Set_string out, "")
; ("--impl", Arg.Set_string (ref ""), "")
; ("--as-ppx", Arg.Set (ref false), "")
; ("--cookie", Arg.Set (ref false), "")
]
in
let anon _ = () in
Arg.parse (Arg.align args) anon "";
let out = open_out !out in
close_out out;

View file

@ -0,0 +1,5 @@
(library
(name other_ppx_api)
(public_name other-ppx.api)
(wrapped false)
(ppx_runtime_libraries other_ppx_runtime))

View file

@ -0,0 +1,4 @@
(library
(name other_ppx_runtime)
(public_name other-ppx.runtime)
(wrapped false))

View file

@ -0,0 +1,23 @@
Demonstrate a bad interaction between cross-compilation and
ppx_runtime_libraries
$ mkdir -p etc/findlib.conf.d
$ export OCAMLFIND_CONF=$PWD/etc/findlib.conf
$ touch etc/findlib.conf etc/findlib.conf.d/foo.conf
$ mkdir lib
$ cat > dune-project <<EOF
> (lang dune 3.8)
> (package (name ppx-cross))
> EOF
$ cat > lib/dune <<EOF
> (library
> (name lib)
> (public_name ppx-cross.lib)
> (preprocess (pps other-ppx.eq)))
> EOF
$ touch lib/lib.ml
$ dune build @install -x foo

View file

@ -0,0 +1,5 @@
(executable
(name p)
(public_name p))
(rule (with-stdout-to file (run ./p.exe)))

View file

@ -0,0 +1,8 @@
(lang dune 1.10)
(context (default))
(context (default
(name cross-1)
(targets foo)
(host default)))

View file

@ -0,0 +1 @@
let () = Printf.printf "%d\n" 137

View file

@ -0,0 +1,8 @@
$ env OCAMLFIND_CONF=$PWD/etc/findlib.conf dune build file @install
File "dune-workspace", lines 5-8, characters 9-65:
5 | (context (default
6 | (name cross-1)
7 | (targets foo)
8 | (host default)))
Error: `targets` and `host` options cannot be used in the same context.
[1]

View file

@ -0,0 +1,87 @@
Test the toolchain field in the workspace.
$ unset OCAMLFIND_TOOLCHAIN
$ unset OCAMLFIND_CONF
First, we create the project
$ cat >dune <<EOF
> (library
> (public_name foo))
> EOF
$ cat >dune-project <<EOF
> (lang dune 3.10)
> (package
> (name foo))
> EOF
$ buildfoo() {
> dune clean
> dune build @install -x foobar
> [ -e _build/default.foobar/foo.cma ] && echo built foo.cma
> }
Now the toolchain:
Now we create the toolchain and make sure we actually use it:
$ actualocamlc="$(command -v ocamlc)"
$ mkdir -p etc/findlib.conf.d
$ cat >etc/findlib.conf <<EOF
> path=""
> ocamlc="$PWD/notocamlc"
> EOF
$ cat >etc/findlib.conf.d/foo.conf <<EOF
> path(foobar)=""
> ocamlc(foobar)="$PWD/notocamlc-foobar"
> EOF
$ cat >notocamlc <<EOF
> #!/usr/bin/env sh
> echo "from notocamlc" >&2
> $actualocamlc \$@
> EOF
$ cat >notocamlc-foobar <<EOF
> #!/usr/bin/env sh
> echo "from notocamlc-foobar" >&2
> $actualocamlc \$@
> EOF
$ chmod +x notocamlc notocamlc-foobar
We set an undefined toolchain with findlib:
$ OCAMLFIND_TOOLCHAIN=foobar buildfoo
ocamlfind: [WARNING] Undefined toolchain: foobar
ocamlfind: [WARNING] Undefined toolchain: foobar
built foo.cma
$ OCAMLFIND_CONF=$PWD/etc/findlib.conf OCAMLFIND_TOOLCHAIN=foobar buildfoo
from notocamlc-foobar
from notocamlc-foobar
from notocamlc-foobar
from notocamlc-foobar
built foo.cma
$ unset OCAMLFIND_TOOLCHAIN
$ unset OCAMLFIND_CONF
Now we set it in the workspace:
$ cat >dune-workspace <<EOF
> (lang dune 1.10)
> (context
> (default
> (toolchain foobar)))
> EOF
$ buildfoo
built foo.cma
$ OCAMLFIND_CONF=$PWD/etc/findlib.conf buildfoo
from notocamlc-foobar
from notocamlc-foobar
from notocamlc-foobar
from notocamlc-foobar
from notocamlc-foobar
from notocamlc-foobar
built foo.cma

View file

@ -0,0 +1,5 @@
(executable
(name p)
(public_name p))
(rule (with-stdout-to file (run ./p.exe)))

View file

@ -0,0 +1,15 @@
(lang dune 1.10)
(context (default))
(context (default
(name cross-1)
(host cross-3)))
(context (default
(name cross-2)
(host cross-1)))
(context (default
(name cross-3)
(host cross-2)))

View file

@ -0,0 +1 @@
let () = Printf.printf "%d\n" 137

View file

@ -0,0 +1,8 @@
$ dune build file @install
File "dune-workspace", lines 13-15, characters 9-50:
13 | (context (default
14 | (name cross-3)
15 | (host cross-2)))
Error: Context 'cross-3' is both a host (for 'cross-1') and a target (for
'cross-2').
[1]