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

Delete ctypes extensions 0.1 and 0.2 #8293

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes/remove-ctypes-versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Remove versions 0.1 and 0.2 of the experimental ctypes extension. (#8293,
@emillon)
7 changes: 2 additions & 5 deletions src/dune_rules/ctypes/ctypes_field.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let syntax =
Dune_lang.Syntax.create
~name
~desc:"the ctypes extension"
[ (0, 1), `Since (3, 0); (0, 2), `Since (3, 4); (0, 3), `Since (3, 7) ]
[ (0, 1), `Deleted_in (3, 11); (0, 2), `Deleted_in (3, 11); (0, 3), `Since (3, 7) ]
;;

module Build_flags_resolver = struct
Expand Down Expand Up @@ -115,10 +115,7 @@ module Function_description = struct
let open Dune_lang.Decoder in
fields
(let+ concurrency = field_o "concurrency" Concurrency_policy.decode
and+ errno_policy =
field_o
"errno_policy"
(Dune_lang.Syntax.since syntax (0, 2) >>> Errno_policy.decode)
and+ errno_policy = field_o "errno_policy" Errno_policy.decode
and+ functor_ = field "functor" Module_name.decode
and+ instance = field "instance" Module_name.decode in
{ concurrency = Option.value concurrency ~default:Concurrency_policy.default
Expand Down
50 changes: 10 additions & 40 deletions src/dune_rules/ctypes/ctypes_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ let build_c_program
~cflags
~output
~deps
~version
=
let ctx = Super_context.context sctx in
let open Memo.O in
Expand Down Expand Up @@ -249,43 +248,15 @@ let build_c_program
]
in
let action =
if version >= (0, 3)
then (
let args =
[ Command.Args.as_any all_flags
; Deps (List.map ~f:(fun s -> Path.relative (Path.build dir) s) source_files)
; A "-o"
; Target (Path.Build.relative dir output)
]
in
let open Action_builder.With_targets.O in
Action_builder.with_no_targets deps >>> Command.run ~dir:(Path.build dir) exe args)
else (
let build =
let absolute_path_hack p =
(* These normal path builder things construct relative paths like
_build/default/your/project/file.c but before dune runs gcc it actually
cds into _build/default, which fails, so we turn them into absolutes to
hack around it. *)
Path.relative (Path.build dir) p |> Path.to_absolute_filename
in
let action =
let open Action_builder.O in
let* flag_args = Command.expand_no_targets ~dir:(Path.build dir) all_flags in
let+ () = deps in
let source_files = List.map source_files ~f:absolute_path_hack in
let output = absolute_path_hack output in
let args = flag_args @ source_files @ [ "-o"; output ] in
(* TODO: it might be possible to convert this to Command.run and
consolidate both branches but it is also possible that we drop
support for < 0.3 instead *)
Action.run exe args
in
Action_builder.with_file_targets
action
~file_targets:[ Path.Build.relative dir output ]
in
Action_builder.With_targets.map ~f:Action.Full.make build)
let args =
[ Command.Args.as_any all_flags
; Deps (List.map ~f:(fun s -> Path.relative (Path.build dir) s) source_files)
; A "-o"
; Target (Path.Build.relative dir output)
]
in
let open Action_builder.With_targets.O in
Action_builder.with_no_targets deps >>> Command.run ~dir:(Path.build dir) exe args
in
Super_context.add_rule sctx ~dir action
;;
Expand Down Expand Up @@ -314,7 +285,7 @@ let exe_link_only ~dir ~shared_cctx ~sandbox program ~deps =
~sandbox
;;

let gen_rules ~cctx ~(buildable : Buildable.t) ~loc ~scope ~dir ~sctx ~version =
let gen_rules ~cctx ~(buildable : Buildable.t) ~loc ~scope ~dir ~sctx =
let ctypes = Option.value_exn buildable.ctypes in
let external_library_name = ctypes.external_library_name in
let type_description_functor = ctypes.type_description.functor_ in
Expand Down Expand Up @@ -422,7 +393,6 @@ let gen_rules ~cctx ~(buildable : Buildable.t) ~loc ~scope ~dir ~sctx ~version =
~output:c_generated_types_cout_exe
~deps
~cflags
~version
in
Super_context.add_rule
sctx
Expand Down
1 change: 0 additions & 1 deletion src/dune_rules/ctypes/ctypes_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ val gen_rules
-> scope:Scope.t
-> dir:Path.Build.t
-> sctx:Super_context.t
-> version:Syntax.Version.t
-> unit Memo.t

val ctypes_cclib_flags
Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/exe_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ let executables_rules
~promote:exes.promote
~embed_in_plugin_libraries
~sandbox
| Some { version; _ } ->
| Some _ ->
(* Ctypes stubgen builds utility .exe files that need to share modules
with this compilation context. To support that, we extract the one-time
run bits from [Exe.build_and_link_many] and run them here, then pass
that to the [Exe.link_many] call here as well as the Ctypes_rules. This
dance is done to avoid triggering duplicate rule exceptions. *)
let* () =
let loc = fst (List.hd exes.Executables.names) in
Ctypes_rules.gen_rules ~cctx ~buildable ~loc ~sctx ~scope ~dir ~version
Ctypes_rules.gen_rules ~cctx ~buildable ~loc ~sctx ~scope ~dir
in
let* () = Module_compilation.build_all cctx in
Exe.link_many
Expand Down
11 changes: 2 additions & 9 deletions src/dune_rules/lib_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -646,15 +646,8 @@ let rules (lib : Library.t) ~sctx ~dir_contents ~dir ~expander ~scope =
let* () =
match buildable.ctypes with
| None -> Memo.return ()
| Some { version; _ } ->
Ctypes_rules.gen_rules
~loc:(fst lib.name)
~cctx
~buildable
~sctx
~scope
~dir
~version
| Some _ ->
Ctypes_rules.gen_rules ~loc:(fst lib.name) ~cctx ~buildable ~sctx ~scope ~dir
in
library_rules lib ~local_lib ~cctx ~source_modules ~dir_contents ~compile_info
in
Expand Down
15 changes: 15 additions & 0 deletions test/blackbox-tests/test-cases/ctypes/delete-0.1.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Version 0.1 is deleted.

$ cat > dune-project << EOF
> (lang dune 3.4)
> (using ctypes 0.1)
> EOF

$ dune build
File "dune-project", line 2, characters 14-17:
2 | (using ctypes 0.1)
^^^
Error: Version 0.1 of the ctypes extension has been deleted in Dune 3.11.
Please port this project to a newer version of the extension, such as 0.3.
Hint: You will also need to upgrade to (lang dune 3.7).
[1]
15 changes: 15 additions & 0 deletions test/blackbox-tests/test-cases/ctypes/delete-0.2.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Version 0.2 is deleted.

$ cat > dune-project << EOF
> (lang dune 3.4)
> (using ctypes 0.2)
> EOF

$ dune build
File "dune-project", line 2, characters 14-17:
2 | (using ctypes 0.2)
^^^
Error: Version 0.2 of the ctypes extension has been deleted in Dune 3.11.
Please port this project to a newer version of the extension, such as 0.3.
Hint: You will also need to upgrade to (lang dune 3.7).
[1]
34 changes: 5 additions & 29 deletions test/blackbox-tests/test-cases/ctypes/directories.t
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
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).
This test checks that relative paths are relative to the directory where rules
are defined, to make sure that vendoring works.

To test that, we create a binding to `BUFSIZ` and `fopen`, both in the C
library. These are provided by `stdio.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)
> (lang dune 3.7)
> (using ctypes 0.3)
> EOF

$ mkdir lib
Expand All @@ -24,7 +22,7 @@ compilation to work.
> (flags :standard -w -27)
> (ctypes
> (build_flags_resolver
> (vendored (c_flags :standard (:include extra_flags.sexp))))
> (vendored (c_flags :standard -I .)))
> (external_library_name l)
> (headers (include lib.h))
> (deps lib.h)
Expand All @@ -37,8 +35,6 @@ compilation to work.
> (generated_entry_point entry)))
> EOF

$ echo "(-I lib -I .)" > lib/extra_flags.sexp

$ cat > lib/lib.h << EOF
> #include <stdio.h>
> EOF
Expand All @@ -64,23 +60,3 @@ compilation to work.
> 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]

With 0.3, everything is relative to the directory.

$ cat > dune-project << EOF
> (lang dune 3.7)
> (using ctypes 0.3)
> EOF

$ echo "(-I .)" > lib/extra_flags.sexp
$ dune build
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ We create a buildable with a ctypes field that declares a duplicate
crash.

$ cat > dune-project << EOF
> (lang dune 3.0)
> (using ctypes 0.1)
> (lang dune 3.7)
> (using ctypes 0.3)
> EOF

$ cat > dune << EOF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ cat >dune-project <<EOF
> (lang dune 3.5)
> (using ctypes 0.1)
> (lang dune 3.7)
> (using ctypes 0.3)
> EOF

$ cat >dune <<EOF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(lang dune 3.4)
(using ctypes 0.2)
(lang dune 3.7)
(using ctypes 0.3)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 3.0)
(using ctypes 0.1)
(lang dune 3.7)
(using ctypes 0.3)
(use_standard_c_and_cxx_flags false)
Loading