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

findlib predicates #5

Open
mobileink opened this issue Sep 9, 2021 · 2 comments
Open

findlib predicates #5

mobileink opened this issue Sep 9, 2021 · 2 comments

Comments

@mobileink
Copy link
Contributor

mobileink commented Sep 9, 2021

findlib META files commonly have both requires(ppx_driver) and requires(-ppx_driver) and similar. For example ppx_sexp_conv.

Currently our default target, e.g. @opam//lib/ppx_sexp_conv:ppx_sexp_conv is based on the ppx_driver predicate. Where we also find -ppx_driver we also have a no_ppx_driver target.

TASK: a second target is not necessary; we can handle this situation with build settings and select on the deps attribute. So instead of:

ocaml_import(
    name = "ppx_sexp_conv",
    version = """v0.14.0""",
    archive = select({
        "@ocaml//mode:bytecode": [
            "//:_lib/ppx_sexp_conv/ppx_sexp_conv.cma",
        ],

        "@ocaml//mode:native": [
            "//:_lib/ppx_sexp_conv/ppx_sexp_conv.cmxa",
            "//:_lib/ppx_sexp_conv/ppx_sexp_conv.a",
        ],

    }),
    deps = [
        "@opam//lib/ppx_sexp_conv/expander",
        "@opam//lib/ppxlib",
    ],
    visibility = ["//visibility:public"]
)

and another `ocaml_import(name = "no_ppx_driver...), we would have something like:

ocaml_import(
    name = "ppx_sexp_conv",
    version = """v0.14.0""",
    archive = select({
        "@ocaml//mode:bytecode": [
            "//:_lib/ppx_sexp_conv/ppx_sexp_conv.cma",
        ],

        "@ocaml//mode:native": [
            "//:_lib/ppx_sexp_conv/ppx_sexp_conv.cmxa",
            "//:_lib/ppx_sexp_conv/ppx_sexp_conv.a",
        ],

    }),
    deps = select({
       "ppx_driver_only": [ ## emulates `-predicates ppx_driver`
            "@opam//lib/ppx_sexp_conv/expander",
            "@opam//lib/ppxlib",
        ],
        "no_ppx_driver_only": [ ## emulates `-predicates -ppx_driver`
            "@opam//lib/ppx_sexp_conv/runtime-lib",
        ],
        "both_disabled": [ ## predicates: -ppx_driver, -custom_ppx,
            "@opam//lib/ppx_deriving",
            "@opam//lib/ppx_sexp_conv/runtime-lib",
        ],
        no_match_error("some error msg...")
    }),
    visibility = ["//visibility:public"]
)
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
bool_flag( name = "ppx_driver", build_setting_default = True )
bool_flag( name = "custom_ppx", build_setting_default = True )

config_setting(name = "ppx_driver_only",
               flag_values = {":ppx_driver": "True",
                              ":custom_ppx": "True"})
config_setting(name = "no_ppx_driver_only",
               flag_values = {":ppx_driver": "False",
                              ":custom_ppx": "True"})
config_setting(name = "both_disabled",
               flag_values = { ":ppx_driver": "False",
                               ":custom_ppx": "False" })

Note that we do not have "//conditions:default" because we want to exclude any combinations we do not explicitly handle, rather than send them to a default resolution. So the effective default is both flags true, which is case ppx_driver_only.

@mobileink
Copy link
Contributor Author

except the flags should be global; put them some place like @opam//ppx/BUILD.bazel

@mobileink
Copy link
Contributor Author

done. @opam//ppx/BUILD.bazel contents:

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

bool_flag( name = "driver", build_setting_default = True )
bool_flag( name = "custom", build_setting_default = True )

config_setting(
    name = "ppx_driver_only",
    flag_values = { ":driver": "True", ":custom": "True" }
)
config_setting(
    name = "no_ppx_driver_only",
    flag_values = { ":driver": "False", ":custom": "True" }
)
config_setting(
    name = "both_disabled",
    flag_values = { ":driver": "False", ":custom": "False" }
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant