From 6dda43fe1443a29cd8016a00b418ce500f6561de Mon Sep 17 00:00:00 2001 From: Killian Delarue Date: Wed, 11 Oct 2023 11:29:22 +0200 Subject: [PATCH 1/2] Manifest: Allow to specify the availability of an opam package --- manifest/manifest.ml | 85 +++++++++++++++++++++++++++++++++++++++++-- manifest/manifest.mli | 23 ++++++++++++ 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/manifest/manifest.ml b/manifest/manifest.ml index 481a1869edfe..d19dd6e2812c 100644 --- a/manifest/manifest.ml +++ b/manifest/manifest.ml @@ -571,6 +571,26 @@ end (* OPAM *) (*****************************************************************************) +type available = + | Always + | Never + | No_32 + | No_x86 + | No_ppc + | No_arm + | No_s390x + | N_ary_and of available list + +let string_of_available = function + | Always -> "Always" + | Never -> "Never" + | No_32 -> "No_32" + | No_x86 -> "No_x86" + | No_ppc -> "No_ppc" + | No_arm -> "No_arm" + | No_s390x -> "No_s390x" + | N_ary_and _ -> "N_ary_and" + type with_test = Always | Never | Only_on_64_arch let show_with_test = function @@ -603,6 +623,7 @@ module Opam = struct depends : dependency list; conflicts : dependency list; build : build_instruction list; + available : available; synopsis : string; url : url option; description : string option; @@ -621,6 +642,7 @@ module Opam = struct depends; conflicts; build; + available; synopsis; url; description; @@ -784,6 +806,23 @@ module Opam = struct | Only_on_64_arch -> ["with-test"; "arch != \"arm32\""; "arch != \"x86_32\""] in + let available = + let rec condition_of_available = function + | No_32 -> + ["arch != \"arm32\""; "arch != \"x86_32\""; "arch != \"ppc32\""] + | No_x86 -> ["arch != \"x86_32\""; "arch != \"x86_64\""] + | No_arm -> ["arch != \"arm32\""; "arch != \"arm64\""] + | No_ppc -> ["arch != \"ppc64\""; "arch != \"ppc64\""] + | No_s390x -> ["arch != \"s390x\""] + | Always -> [] + | Never -> ["false"] + | N_ary_and available_list -> + List.map condition_of_available available_list + |> List.flatten + |> deduplicate_list (fun s -> s) + in + condition_of_available available + in let pp_condition fmt = function | [] -> () | ["with-test"] -> Format.pp_print_string fmt " {with-test}" @@ -861,6 +900,13 @@ module Opam = struct (pp_list ~v:true ~prefix:"conflicts: " pp_dependency) conflicts ; pp_line "%a" (pp_list ~prefix:"build: " pp_build_instruction) build ; + if available <> [] then + pp_line + "available: %a" + (Format.pp_print_list + ~pp_sep:(fun fmt () -> Format.pp_print_string fmt " & ") + Format.pp_print_string) + available ; pp_line "synopsis: %a" pp_string synopsis ; Option.iter pp_url url ; Option.iter (pp_line "description: %a" pp_string) description @@ -1175,6 +1221,7 @@ module Target = struct static : bool; synopsis : string option; description : string option; + available : available; virtual_modules : string list; default_implementation : string option; npm_deps : Npm.t list; @@ -1358,6 +1405,7 @@ module Target = struct ?synopsis:string -> ?description:string -> ?time_measurement_ppx:bool -> + ?available:available -> ?virtual_modules:string list -> (* A note on [default_implementation]. In the .mli, this argument is given type [string] instead of [target]. This is because one can't @@ -1428,9 +1476,10 @@ module Target = struct ?(optional = false) ?(preprocess = []) ?(preprocessor_deps = []) ?(private_modules = []) ?profile ?(opam_only_deps = []) ?(release_status = Auto_opam) ?static ?synopsis ?description - ?(time_measurement_ppx = false) ?(virtual_modules = []) - ?default_implementation ?(cram = false) ?license ?(extra_authors = []) - ?(with_macos_security_framework = false) ~path names = + ?(time_measurement_ppx = false) ?(available : available = Always) + ?(virtual_modules = []) ?default_implementation ?(cram = false) ?license + ?(extra_authors = []) ?(with_macos_security_framework = false) ~path names + = let conflicts = List.filter_map Fun.id conflicts in let deps = List.filter_map Fun.id deps in let opam_only_deps = List.filter_map Fun.id opam_only_deps in @@ -1786,6 +1835,7 @@ module Target = struct synopsis; description; npm_deps; + available; virtual_modules; default_implementation; cram; @@ -2294,6 +2344,7 @@ module Sub_lib = struct ?synopsis ?description ?time_measurement_ppx + ?available ?virtual_modules ?default_implementation ?cram @@ -2372,6 +2423,7 @@ module Sub_lib = struct ?static ?description ?time_measurement_ppx + ?available ?virtual_modules ?default_implementation ?cram @@ -3031,6 +3083,30 @@ let generate_opam ?release for_package (internals : Target.internal list) : in deduplicate_list ~merge (fun {Opam.package; _} -> package) depends in + let merge_available a b = + match (a, b) with + | No_32, No_32 -> No_32 + | No_arm, No_arm -> No_arm + | No_x86, No_x86 -> No_x86 + | No_ppc, No_ppc -> No_ppc + | Never, _ | _, Never -> Never + | Always, Always -> Always + | N_ary_and available_list_1, N_ary_and available_list_2 -> + N_ary_and + (deduplicate_list + string_of_available + (available_list_1 @ available_list_2)) + | N_ary_and available_list, a | a, N_ary_and available_list -> + N_ary_and (deduplicate_list string_of_available (a :: available_list)) + | a1, a2 -> N_ary_and [a1; a2] + in + let available = + List.fold_left + (fun (available : available) (internal : Target.internal) -> + merge_available available internal.available) + Always + internals + in let conflicts = List.of_seq @@ Opam_dependency_set.to_seq @@ List.fold_left @@ -3175,6 +3251,7 @@ let generate_opam ?release for_package (internals : Target.internal list) : depends; conflicts; build; + available; synopsis = get_consistent_value ~name:"synopsis" (fun x -> x.synopsis); url = Option.map (fun {url; _} -> url) release; description; @@ -3225,6 +3302,7 @@ let generate_opam_meta_package opam_release_graph add_to_meta_package : Opam.t = depends = depends1 @ depends2; conflicts = []; build = []; + available = Always; synopsis = "Main virtual package for Octez, an implementation of Tezos"; url = None; description = None; @@ -3862,6 +3940,7 @@ let generate_profiles ~default_profile = depends; conflicts; build = []; + available = Always; synopsis = Printf.sprintf "Virtual package depending on Octez dependencies (profile: %s)" diff --git a/manifest/manifest.mli b/manifest/manifest.mli index a5588c39aa8e..41c62920170c 100644 --- a/manifest/manifest.mli +++ b/manifest/manifest.mli @@ -574,6 +574,28 @@ type inline_tests (** Declare an inline_tests backend. *) val inline_tests_backend : target -> inline_tests +(** Used to specify the availability of an opam package. + + - [Always]: The package is always available. + No entry will be added to the opam file. + - [Never]: The package will be marked as unavailable. + - [No_32]: The package is marked as unavailable on all 32-bits architectures. + - [No_x86]: The package is marked as unavailable on x86 architectures. + - [No_ppc]: The package is marked as unavailable on ppc architectures. + - [No_arm]: The package is marked as unavailable on arm architectures. + - [N_ary_and [a1;...;an]]: The package availability is [a1] & ... & [an]. + +*) +type available = + | Always + | Never + | No_32 + | No_x86 + | No_ppc + | No_arm + | No_s390x + | N_ary_and of available list + (** Whether to add the [dune runtest] command in the [.opam] file. - [Never]: do not add it. @@ -832,6 +854,7 @@ type 'a maker = ?synopsis:string -> ?description:string -> ?time_measurement_ppx:bool -> + ?available:available -> ?virtual_modules:string list -> ?default_implementation:string -> ?cram:bool -> -- GitLab From 49500ae9a0321edfbd26ee811f4a768671beb149 Mon Sep 17 00:00:00 2001 From: Killian Delarue Date: Wed, 11 Oct 2023 11:30:20 +0200 Subject: [PATCH 2/2] Manifest: Mark bls12 as unavailable on arm32 and x86_32 --- manifest/main.ml | 1 + opam/bls12-381.opam | 1 + 2 files changed, 2 insertions(+) diff --git a/manifest/main.ml b/manifest/main.ml index f3bbd27a7916..59effdad8243 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -959,6 +959,7 @@ let bls12_381 = public_lib "bls12-381" ~path:"src/lib_bls12_381" + ~available:(N_ary_and [No_32; No_ppc; No_s390x]) ~synopsis: "Implementation of the BLS12-381 curve (wrapper for the Blst library)" ~modules: diff --git a/opam/bls12-381.opam b/opam/bls12-381.opam index e1f36218e3e7..0cdfad739be2 100644 --- a/opam/bls12-381.opam +++ b/opam/bls12-381.opam @@ -24,4 +24,5 @@ build: [ ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] +available: arch != "arm32" & arch != "x86_32" & arch != "ppc32" & arch != "ppc64" & arch != "s390x" synopsis: "Implementation of the BLS12-381 curve (wrapper for the Blst library)" -- GitLab