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

[bazel] Integrate packages #92220

Closed
tylersmalley opened this issue Feb 22, 2021 · 2 comments
Closed

[bazel] Integrate packages #92220

tylersmalley opened this issue Feb 22, 2021 · 2 comments
Assignees
Labels
Feature:Build Packaging impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort Team:Operations Team label for Operations Team

Comments

@tylersmalley
Copy link
Contributor

tylersmalley commented Feb 22, 2021

In this phase, we set out to provide the necessary infrastructure outlined previously to begin utilizing Bazel and begin doing so by migrating the current 38 packages.

A BUILD.bazel file will be added to the root of each package defining a build target. This filegroup target will be what we call during the bootstrap phase to build all packages migrated to Bazel. This target is temporary to maintain similar functionality during our transition. In the future, these procedural build steps will be removed in favor of dependency, tree-driven actions where work will only be done if it’s necessary for the given task like running the Kibana server or executing a unit test.

The @kbn/pm package will be updated to allow for the existing legacy builds to run in parallel with the new packages build target, invoked by calling bazel build //packages:build.

The build targets will no longer reside within the package themselves and instead will be within the bazel/bin directory. To account for this, any defined dependency on this will need to be updated to reference the new directory (example: link:bazel/bin/packages/elastic-datemath). While also in this transition period, the build will need to copy over the packages from bazel/bin into the node_modules of the build target.

Example package BUILD.bazel for packages/elastic-datemath:

load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library")

SRCS = [
    ".npmignore",
    "index.js",
    "index.d.ts",
    "package.json",
    "readme",
    "tsconfig.json",
]

filegroup(
    name = "src",
    srcs = glob(SRCS),
)

js_library(
    name = "elastic-datemath",
    srcs = [ ":src" ],
    deps = [ "@npm//moment" ],
    package_name = "@elastic/datemath",
    visibility = ["//visibility:public"],
)

alias(
    name = "build",
    actual = "elastic-datemath",
    visibility = ["//visibility:public"],
)

If the package has unit tests, they will need to also be migrated to be invoked with bazel test as described in the Unit Testing section.

Within Bazel, the packages will have new overall rules:

  • It cannot contain build scripts. Every package build will be written using a Bazel BUILD.bazel file
  • It cannot have side effects. Every package build should be cacheable and reproducible and should not produce any side effects
  • Each package should define three major public target rules on Bazel BUILD.bazel files: build, jest, and a js_library target with the same name of the folder where the package is living.
  • Each package should have a set of npm scripts. The required ones are: build, watch. The optional ones are: test. The build script should just invoke “bazel build //packages/package_name:build”; The watch should call build with ibazel and pass the arguments “-- -node_options=--inspect-brk” like “ibazel build //packages/package_name:build -- -node_options=--inspect-brk” (need to test this) and finally for packages that define jest tests we should define a script that will call the unit tests target rule like bazel test //packages/package_name:jest
  • In order to output its targets in the most Bazel friendly way, each package will output its target according to the following folder structure: for node targets, it will be target_server, for web target it will be target_web and for types, it will be target_types.
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@mistic mistic mentioned this issue Mar 1, 2021
23 tasks
@tylersmalley tylersmalley added 1 and removed 1 labels Oct 11, 2021
@exalate-issue-sync exalate-issue-sync bot added impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort labels Nov 5, 2021
@tylersmalley
Copy link
Contributor Author

This has been completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Build Packaging impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort Team:Operations Team label for Operations Team
Projects
None yet
Development

No branches or pull requests

4 participants