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

Ctypes binding doesn't support well local headers #5325

Closed
bobot opened this issue Jan 10, 2022 · 9 comments · Fixed by #6883 or ocaml/opam-repository#23349
Closed

Ctypes binding doesn't support well local headers #5325

bobot opened this issue Jan 10, 2022 · 9 comments · Fixed by #6883 or ocaml/opam-repository#23349
Labels

Comments

@bobot
Copy link
Collaborator

bobot commented Jan 10, 2022

Local headers are not well supported with the ctypes, the tests with vendored stanza makes it clear:

(vendored
; hack: multiple -I directives to work around cc commands being run from different
; relative directories. Is there a cleaner way to do this?
(c_flags ("-Istubgen/vendor" "-Ivendor"))))
(headers (include "example.h"))

having (headers (local <file>)) or (headers (include_dirs <dir>)) which would add the correct dependencies and the correct -I according to the current working directory would make the vendor feature more usable.

CC @mbacarella

@bobot
Copy link
Collaborator Author

bobot commented Jan 11, 2022

Moreovere I'm not sure that the headers of installed libraries are used by ctypes sub-stanza. For example adding (libraries zarith) doesn't make zarith.h available.

@mbacarella
Copy link
Collaborator

I agree this part sucks. Something that would be nice to fix for v0.2.

For example adding (libraries zarith) doesn't make zarith.h available.

This is probable. What machinery in dune sets this up?

@bobot
Copy link
Collaborator Author

bobot commented Jan 11, 2022

What machinery in dune sets this up?

What do you mean? The set of libraries and there location should be easy to get and also adding the right options to the compilation phase of ctypes. With the points of view of the user, the goal would just be to ensures this of the documentation.

@bobot
Copy link
Collaborator Author

bobot commented Jan 16, 2022

I also have difficulties with the compilation of the generated stubs. I had to set (use_standard_c_and_cxx_flags false) because I was unable to get -fpicadded. I don't know how to add :standardto cflags and lflags. At least the documentation of the ctypes sub-stanza should mention it before final 3.0. The ctypes feature is experimental, but I would prefer to document the current known shortcoming so that people don't lose too much time.

CC @voodoos

@mbacarella
Copy link
Collaborator

mbacarella commented Feb 20, 2022

having (headers (local )) or (headers (include_dirs <dir>)) which would add the correct dependencies and the correct -I according to the current working directory would make the vendor feature more usable.

Sounds promising. Let's formalize this a bit more. Right now the headers directive type is:

module Headers : sig
  type t =
    | Include of string list
    | Preamble of string
end

At the very least here we've talked about

module Headers : sig
  type t =
    (* 'preamble' pastes the string into the top of the C stubs, no extra dune rules *)
    | Preamble of string
    (* 'include' emits [#include <file.h>]s, no extra dune rules *)
    | Include of string list
    (* 'local' is like 'include', but also adds a dune rule dep for each file in the list *)
    | Local of string list
    (* `include_dirs` adds a dependency to each dir in the list, and emits a C
        compiler `-I` for each dir as well *)
    | Include_dirs of string list
end

To provide flexibility for arbitrarily weird cases, we would probably want to allow repeated use of (headers ...) stanza, evaluated in the order they appear in the dune-file.

Does this sound encompassing enough?

@bobot
Copy link
Collaborator Author

bobot commented Feb 21, 2022

It seems very nice for the vendor case. For include_dirs, would it be a glob? Perhaps the deps field of #5346 is enough and can stay in a final version. So only local?

Remains something for the ocaml library case:

  • we can document and test the %{lib:zarith}/zarith.h, and precise this documentation
  • we have something more automatic, but harder to design right.

nitpick: I believe it will be Path.Build.t instead of string for the two new cases.

@bobot
Copy link
Collaborator Author

bobot commented Mar 12, 2022

@mbacarella additionally since 2418f62 we can't use -I %{lib:zarith:.} in order to include lib directory, and ctypes doesn't support include_dirs of foreign_stubs

EDIT: more precisely ìnclude_dirs can be added in foreign_stubs in parallel to a ctypes, but it failed when no (names ...) is given. Perhaps something need to be fixed, but perhaps also include_dirs from a library can be added alsodirectly to ctypes.

@bobot
Copy link
Collaborator Author

bobot commented Mar 16, 2022

Also -Idir breaks when vendoring the library, such contraption are needed: bobot/ocaml-flint@630a749 . Perhaps a %{pwd} would be nice.

emillon added a commit to emillon/dune that referenced this issue Jan 6, 2023
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>
emillon added a commit to emillon/dune that referenced this issue Jan 9, 2023
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>
emillon added a commit to emillon/dune that referenced this issue Jan 10, 2023
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>
emillon added a commit that referenced this issue Jan 10, 2023
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 #5325.

Signed-off-by: Etienne Millon <me@emillon.org>

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to emillon/dune that referenced this issue Jan 13, 2023
This creates version 0.3 of the ctypes field.

When used, commands are run in the directory where the corresponding
stanza is defined. This makes it possible to use relative directories.
See ocaml#5325.
emillon added a commit to emillon/dune that referenced this issue Jan 30, 2023
This creates version 0.3 of the ctypes field.

When used, commands are run in the directory where the corresponding
stanza is defined. This makes it possible to use relative directories.
See ocaml#5325.
@emillon
Copy link
Collaborator

emillon commented Jan 30, 2023

I consider that #6883 fixes this since it's now possible to refer to local headers using a relative path. This does not encompass every use case so please open feature requests if necessary.

emillon added a commit to emillon/dune that referenced this issue Jan 30, 2023
This creates version 0.3 of the ctypes field.

When used, commands are run in the directory where the corresponding
stanza is defined. This makes it possible to use relative directories.

Fixes ocaml#5325

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to emillon/dune that referenced this issue Feb 6, 2023
This creates version 0.3 of the ctypes field.

When used, commands are run in the directory where the corresponding
stanza is defined. This makes it possible to use relative directories.

Fixes ocaml#5325

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to emillon/dune that referenced this issue Feb 6, 2023
This creates version 0.3 of the ctypes field.

When used, commands are run in the directory where the corresponding
stanza is defined. This makes it possible to use relative directories.

Fixes ocaml#5325

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to emillon/dune that referenced this issue Feb 8, 2023
This creates version 0.3 of the ctypes field.

When used, commands are run in the directory where the corresponding
stanza is defined. This makes it possible to use relative directories.

Fixes ocaml#5325

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to emillon/dune that referenced this issue Feb 9, 2023
This creates version 0.3 of the ctypes field.

When used, commands are run in the directory where the corresponding
stanza is defined. This makes it possible to use relative directories.

Fixes ocaml#5325

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit that referenced this issue Feb 9, 2023
This creates version 0.3 of the ctypes field.

When used, commands are run in the directory where the corresponding
stanza is defined. This makes it possible to use relative directories.

Fixes #5325

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to emillon/opam-repository that referenced this issue Feb 17, 2023
…, dune-rpc, dune-rpc-lwt, dune-private-libs, dune-glob, dune-configurator, dune-build-info, dune-action-plugin and chrome-trace (3.7.0)

CHANGES:

- Allow running `$ dune exec` in watch mode (with the `-w` flag). In watch mode,
  `$ dune exec` the executed binary whenever it is recompiled. (ocaml/dune#6966,
  @gridbugs)

- `coqdep` is now called once per theory, instead of one time per Coq
  file. This should significantly speed up some builds, as `coqdep`
  startup time is often heavy (ocaml/dune#7048, @Alizter, @ejgallego)

- Add `map_workspace_root` dune-project stanza to allow disabling of
  mapping of workspace root to `/workspace_root`. (ocaml/dune#6988, fixes ocaml/dune#6929,
  @richardlford)

- Fix handling of support files generated by odoc. (ocaml/dune#6913, @jonludlam)

- Fix parsing of OCaml errors that contain code excerpts with `...` in them.
  (ocaml/dune#7008, @rgrinberg)

- Pre-emptively clear screen in watch mode (ocaml/dune#6987, fixes ocaml/dune#6884, @rgrinberg)

- Fix cross compilation configuration when a context with targets is itself a
  host of another context (ocaml/dune#6958, fixes ocaml/dune#6843, @rgrinberg)

- Fix parsing of the `<=` operator in *blang* expressions of `dune` files.
  Previously, the operator would be interpreted as `<`. (ocaml/dune#6928, @tatchi)

- Fix `--trace-file` output. Dune now emits a single *complete* event for every
  executed process. Unterminated *async* events are no longer written. (ocaml/dune#6892,
  @rgrinberg)

- Fix preprocessing with `staged_pps` (ocaml/dune#6748, fixes ocaml/dune#6644, @rgrinberg)

- Use colored output with MDX when Dune colors are enabled.
  (ocaml/dune#6462, @MisterDA)

- Make `dune describe workspace` return consistent dependencies for
  executables and for libraries. By default, compile-time dependencies
  towards PPX-rewriters are from now not taken into account (but
  runtime dependencies always are). Compile-time dependencies towards
  PPX-rewriters can be taken into account by providing the
  `--with-pps` flag. (ocaml/dune#6727, fixes ocaml/dune#6486, @esope)

- Print missing newline after `$ dune exec`. (ocaml/dune#6821, fixes ocaml/dune#6700, @rgrinberg,
  @Alizter)

- Fix binary corruption when installing or promoting in parallel (ocaml/dune#6669, fixes
  ocaml/dune#6668, @edwintorok)

- Use colored output with GCC and Clang when compiling C stubs. The
  flag `-fdiagnostics-color=always` is added to the `:standard` set of
  flags. (ocaml/dune#4083, @MisterDA)

- Fix the parsing of decimal and hexadecimal escape literals in `dune`,
  `dune-package`, and other dune s-expression based files (ocaml/dune#6710, @shym)

- Report an error if `dune init ...` would create a "dune" file in a location
  which already contains a "dune" directory (ocaml/dune#6705, @gridbugs)

- Fix the parsing of alerts. They will now show up in diagnostics correctly.
  (ocaml/dune#6678, @rginberg)

- Fix the compilation of modules generated at link time when
  `implicit_transitive_deps` is enabled (ocaml/dune#6642, @rgrinberg)

- Allow `$ dune utop` to load libraries defined in data only directories
  defined using `(subdir ..)` (ocaml/dune#6631, @rgrinberg)

- Format dune files when they are named `dune-file`. This occurs when we enable
  the alternative file names project option. (ocaml/dune#6566, @rgrinberg)

- Move `$ dune ocaml-merlin -dump-config=$dir` to `$ dune ocaml merlin
  dump-config $dir`. (ocaml/dune#6547, @rgrinberg)

- Allow compilation rules to be impacted by `(env ..)` stanzas that modify the
  environment or set binaries. (ocaml/dune#6527, @rgrinberg)

- Coq native mode is now automatically detected by Dune starting with Coq lang
  0.7. `(mode native)` has been deprecated in favour of detection from the
  configuration of Coq. (ocaml/dune#6409, @Alizter)

- Print "Leaving Directory" whenever "Entering Directory" is printed. (ocaml/dune#6419,
  fixes ocaml/dune#138, @cpitclaudel, @rgrinberg)

- Allow `$ dune ocaml dump-dot-merlin` to run in watch mode. Also this command
  shouldn't print "Entering Directory" mesages. (ocaml/dune#6497, @rgrinberg)

- `dune clean` should no longer fail under Windows due to the inability to
  remove the `.lock` file. Also, bring the implementation of the global lock
  under Windows closer to that of Unix. (ocaml/dune#6523, @nojb)

- Remove "Entering Directory" messages for `$ dune install`. (ocaml/dune#6513,
  @rgrinberg)

- Stop passing `-q` flag in `dune coq top`, which allows for `.coqrc` to be
  loaded. (ocaml/dune#6848, fixes ocaml/dune#6847, @Alizter)

- Fix missing dependencies when detecting the kind of C compiler we're using
  (ocaml/dune#6610, fixes ocaml/dune#6415, @emillon)

- Allow `(include_subdirs qualified)` for OCaml projects. (ocaml/dune#6594, fixes ocaml/dune#1084,
  @rgrinberg)

- Accurately determine merlin configuration for all sources selected with
  `copy#` and `copy_files#`. The old heuristic of looking for a module in
  parent directories is removed (ocaml/dune#6594, @rgrinberg)

- Fix inline tests with *js_of_ocaml* and whole program compilation mode
  enabled (ocaml/dune#6645, @hhugo)

- Fix *js_of_ocaml* separate compilation rules when `--enable=effects`
  ,`--enable=use-js-string` or `--toplevel` is used. (ocaml/dune#6714, ocaml/dune#6828, ocaml/dune#6920, @hhugo)

- Fix *js_of_ocaml* separate compilation in presence of linkall (ocaml/dune#6832, ocaml/dune#6916, @hhugo)

- Remove spurious build dir created when running `dune init proj ...` (ocaml/dune#6707,
  fixes ocaml/dune#5429, @gridbugs)

- Allow `--sandbox` to affect `ocamldep` invocations. Previously, they were
  wrongly marked as incompatible (ocaml/dune#6749, @rgrinberg)

- Validate the command line arguments for `$ dune ocaml top-module`. This
  command requires one positional argument (ocaml/dune#6796, fixes ocaml/dune#6793, @rgrinberg)

- Add a `dune cache size` command for displaying the size of the cache (ocaml/dune#6638,
  @Alizter)

- Fix dependency cycle when installing files to the bin section with
  `glob_files` (ocaml/dune#6764, fixes ocaml/dune#6708, @gridbugs)

- Handle "Too many links" errors when using Dune cache on Windows (ocaml/dune#6993, @nojb)

- Allow the `cinaps` stanza to set a custom alias. By default, if the alias is
  not set then the cinaps actions will be attached to both `@cinaps` and
  `@runtest` (ocaml/dune#6991, @rgrinberg)

- Add `(using ctypes 0.3)`. When used, paths in `(ctypes)` are interpreted
  relative to where the stanza is defined. (ocaml/dune#6883, fixes ocaml/dune#5325, @emillon)

- Auto-detect `dune-workspace` files as `dune` files in Emacs (ocaml/dune#7061,
  @ilankri)

- Add native support for polling mode on Windows (ocaml/dune#7010, @yams-yams, @nojb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment