apple / rules_pkl

Bazel build rules for Pkl
Apache License 2.0
22 stars 6 forks source link

`pkl_project` should have `extra_flags` attribute like `pkl_package` #23

Open asalah33 opened 15 hours ago

asalah33 commented 15 hours ago

Context

In this line in pkl_project.bzl https://github.com/apple/rules_pkl/blob/6317523342e42ef608aa390444b1ea01fb4a5176/pkl/private/pkl_project.bzl#L68

it doesn't accept any other flags. so, if we have a PklProject file that has read("env:MY_VAR") within. Our only option is to export MY_VAR as OS env var.

This limits our options and add more complexity at our side if we cannot export MY_VAR as OS env var.

Given that pkl_package solves this issue by accepting extra_flags attribute https://github.com/apple/rules_pkl/blob/6317523342e42ef608aa390444b1ea01fb4a5176/pkl/private/pkl_package.bzl#L85 I think we can use the same approach and add extra_flags attribute to pkl_project as well which will simplify Bazel code at user-side by a margin

Example

consider this example PklProject file

amends "pkl:Project"

package {
  name = "my_package_project"
  version = read("env:MY_VERSION")
  authors {
    "someone@someplace.com"
  }
  baseUri = "package://someplace.com/my-repol/\(name)"
  packageZipUrl = "https://someplace.com/my-repol/\(name)@\(version).zip"
}

with this example BUILD.bazel file:

pkl_project(
    name = "my_pkl_project",
    pkl_project = "//my_target:PklProject",
    pkl_project_deps = "//my_target:PklProject.deps.json",
)

pkl_package(
    name = "pkl-package",
    srcs = [
        "my-file.pkl",
    ],
    label = "my_pkl_label",
    project = "@my_pkl_project//:project",
)

if I tried to do bazel build //my_target:my_pkl_project it will fail with Cannot find resource env: MY_VERSION

Current State:

To allow the build command to succeed, it should be changed to MY_VERSION=1.0.0 bazel build //my_target:pkl-package --action_env=MY_VERSION

Desired State:

We need to add support for passing the version from other Bazel variable, like:

pkl_project(
    name = "my_pkl_project",
    pkl_project = "//my_target:PklProject",
    pkl_project_deps = "//my_target:PklProject.deps.json",
    extra_flags = ["-e", "MY_VERSION=1.0.0"]
)