forked from ocaml/dune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ctypes and relative include paths
This adds a test that shows that under `(using ctypes 0.2)`, local headers need to be added in two different locations because rules are executed from different places. See ocaml#5325. Signed-off-by: Etienne Millon <me@emillon.org>
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
This test characterizes how the ctypes support deals with directories, in | ||
particular when relative paths are passed as `-I`. | ||
|
||
With `(using ctypes 0.2)`, some commands are executed in workspace root and | ||
others are executed in the directory where `(ctypes)` is found, so it is | ||
necessary to pass relative dirs twice. (this prevents vendorability, since this | ||
requires knowing the path from the workspace root to the current directory). | ||
|
||
To test that, we create a binding to `O_RDWR` and `open`, both in the C library. | ||
These are provided by `fcntl.h`, but instead of using this header, we're | ||
proxying it through a `lib.h` which should be in the include path for | ||
compilation to work. | ||
|
||
$ cat > dune-project << EOF | ||
> (lang dune 3.4) | ||
> (using ctypes 0.2) | ||
> EOF | ||
|
||
$ mkdir lib | ||
|
||
$ cat > lib/dune << EOF | ||
> (executable | ||
> (name e) | ||
> (flags :standard -w -27) | ||
> (ctypes | ||
> (build_flags_resolver | ||
> (vendored (c_flags :standard (:include extra_flags.sexp)))) | ||
> (external_library_name l) | ||
> (headers (include lib.h)) | ||
> (deps lib.h) | ||
> (type_description | ||
> (functor f) | ||
> (instance types)) | ||
> (function_description | ||
> (functor f) | ||
> (instance functions)) | ||
> (generated_entry_point entry))) | ||
> EOF | ||
|
||
$ echo "(-I lib -I .)" > lib/extra_flags.sexp | ||
|
||
$ cat > lib/lib.h << EOF | ||
> #include <fcntl.h> | ||
> EOF | ||
|
||
$ cat > lib/e.ml << EOF | ||
> let () = Printf.printf "%d\n" Entry.Types.rdwr | ||
> let (_:char Ctypes.ptr -> int -> int) = Entry.Functions.open_ | ||
> EOF | ||
|
||
$ cat > lib/f.ml << EOF | ||
> module Types(F:Ctypes.TYPE) = struct | ||
> open F | ||
> let rdwr = constant "O_RDWR" int | ||
> end | ||
> | ||
> module Functions(F:Ctypes.FOREIGN) = struct | ||
> open Ctypes | ||
> open F | ||
> let open_ = foreign "open" (ptr char @-> int @-> returning int) | ||
> end | ||
> EOF | ||
|
||
$ dune build | ||
|
||
We ensure that just `-I lib` or `-I .` are not enough on their own. | ||
|
||
$ echo "(-I lib)" > lib/extra_flags.sexp | ||
$ dune build > /dev/null 2>&1 | ||
[1] | ||
|
||
$ echo "(-I .)" > lib/extra_flags.sexp | ||
$ dune build > /dev/null 2>&1 | ||
[1] |