diff --git a/test/blackbox-tests/test-cases/ctypes/directories.t b/test/blackbox-tests/test-cases/ctypes/directories.t new file mode 100644 index 000000000000..4f040fe7792d --- /dev/null +++ b/test/blackbox-tests/test-cases/ctypes/directories.t @@ -0,0 +1,77 @@ +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 + + $ mk_dune () { + > local flags=$1 + > cat << EOF + > (executable + > (name e) + > (flags :standard -w -27) + > (ctypes + > (build_flags_resolver + > (vendored (c_flags :standard $flags))) + > (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 + > } + + $ mk_dune "-I lib -I ." > lib/dune + + $ cat > lib/lib.h << EOF + > #include + > 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. + + $ mk_dune "-I lib" > lib/dune + $ dune build > /dev/null 2>&1 + [1] + + $ mk_dune "-I ." > lib/dune + $ dune build > /dev/null 2>&1 + [1]