diff --git a/.buckconfig b/.buckconfig index 5bf55e16ba66d..06522aaf2a170 100644 --- a/.buckconfig +++ b/.buckconfig @@ -1,6 +1,6 @@ [repositories] -root = . prelude = prelude +buck2 = . shim = shim [repository_aliases] @@ -14,4 +14,4 @@ buck = shim bazel_skylib = shim [parser] -target_platform_detector_spec = target:root//...->prelude//platforms:default target:shim//...->prelude//platforms:default +target_platform_detector_spec = target:buck2//...->prelude//platforms:default target:shim//...->prelude//platforms:default diff --git a/docs/users/advanced/buck2_library.md b/docs/users/advanced/buck2_library.md new file mode 100644 index 0000000000000..ac2d23d6fe20d --- /dev/null +++ b/docs/users/advanced/buck2_library.md @@ -0,0 +1,32 @@ +--- +id: buck2_library +title: Consuming code from the `buck2` repository +--- + +It is possible to depend on targets from the Buck2 repository, which you +might need to do to write a custom test runner (at least until [TestInfo +V2](../../rfcs/drafts/test-info-v2.md) lands). Note that there are no +API stability guarantees at the moment. + +The Buck2 Rust code is available in the `buck2` cell and is useable as +is after adding the following to your `.buckconfig`'s (assuming that the +`buck2` project is available at `path/to/buck2`): + +``` +[cells] +buck2 = path/to/buck2 +shim = path/to/buck2/shim + +[cell_aliases] +config = prelude +ovr_config = prelude +fbcode = shim +fbsource = shim +fbcode_macros = shim +buck = shim +bazel_skylib = shim +``` + +Note that due to how cells work in Buck2, the `buck2` cell cannot bring +its own dependencies, so you must remove conflicting cell aliases from +`path/to/buck2/.buckconfig`. diff --git a/examples/visual_studio/toolchains/BUCK b/examples/visual_studio/toolchains/BUCK index aff99e75f953b..66a05034e733f 100644 --- a/examples/visual_studio/toolchains/BUCK +++ b/examples/visual_studio/toolchains/BUCK @@ -24,13 +24,13 @@ system_cxx_toolchain( "/permissive-", "/TC", ] + select({ - "root//buck2_utils/configuration:debug": [ + "buck2//buck2_utils/configuration:debug": [ "/Od", "/D_DEBUG", "/RTC1", "/MDd", ], - "root//buck2_utils/configuration:release": [ + "buck2//buck2_utils/configuration:release": [ "/O2", "/Oi", "/GL", @@ -67,13 +67,13 @@ system_cxx_toolchain( "/permissive-", "/TP", ] + select({ - "root//buck2_utils/configuration:debug": [ + "buck2//buck2_utils/configuration:debug": [ "/Od", "/D_DEBUG", "/RTC1", "/MDd", ], - "root//buck2_utils/configuration:release": [ + "buck2//buck2_utils/configuration:release": [ "/O2", "/Oi", "/GL", @@ -94,9 +94,9 @@ system_cxx_toolchain( "/DEBUG", "/INCREMENTAL:NO", ] + select({ - "root//buck2_utils/configuration:debug": [], + "buck2//buck2_utils/configuration:debug": [], #Converted /LTCG:incremental to /LTCG because I'm guessing incremental actions won't work well with Buck2 - "root//buck2_utils/configuration:release": [ + "buck2//buck2_utils/configuration:release": [ "/OPT:REF", "/OPT:ICF", "/LTCG", @@ -116,6 +116,6 @@ configuration = read_config("cxx", "configuration", "debug") platform( name = "default", - constraint_values = ["root//buck2_utils/configuration:release"] if configuration == "release" else ["root//buck2_utils/configuration:debug"], + constraint_values = ["buck2//buck2_utils/configuration:release"] if configuration == "release" else ["buck2//buck2_utils/configuration:debug"], deps = ["prelude//platforms:default"], ) diff --git a/shim/build_defs/native_rules.bzl b/shim/build_defs/native_rules.bzl index a3e3a7039b0f3..1e7d3f6a00972 100644 --- a/shim/build_defs/native_rules.bzl +++ b/shim/build_defs/native_rules.bzl @@ -18,7 +18,7 @@ def buck_filegroup(visibility = ["PUBLIC"], **kwargs): def alias(actual, visibility = ["PUBLIC"], **kwargs): if actual.startswith("//buck2/"): - actual = "root//" + actual.removeprefix("//buck2/") + actual = "buck2//" + actual.removeprefix("//buck2/") native.alias(actual = actual, visibility = visibility, **kwargs) def buck_sh_binary(visibility = ["PUBLIC"], **kwargs): diff --git a/shim/shims.bzl b/shim/shims.bzl index 242e9d174c2d5..288f1f5c663a1 100644 --- a/shim/shims.bzl +++ b/shim/shims.bzl @@ -416,9 +416,9 @@ def _fix_dep(x: str) -> [ elif x.startswith("//buck2/facebook/"): return None elif x.startswith("//buck2/"): - return "root//" + x.removeprefix("//buck2/") + return "buck2//" + x.removeprefix("//buck2/") elif x.startswith("fbcode//common/ocaml/interop/"): - return "root//" + x.removeprefix("fbcode//common/ocaml/interop/") + return "buck2//" + x.removeprefix("fbcode//common/ocaml/interop/") elif x.startswith("fbcode//third-party-buck/platform010/build/supercaml"): return "shim//third-party/ocaml" + x.removeprefix("fbcode//third-party-buck/platform010/build/supercaml") elif x.startswith("fbcode//third-party-buck/platform010/build"): @@ -430,12 +430,12 @@ def _fix_dep(x: str) -> [ elif x.startswith("//folly"): oss_depends_on_folly = read_config("oss_depends_on", "folly", False) if oss_depends_on_folly: - return "root//folly/" + x.removeprefix("//") - return "root//" + x.removeprefix("//") - elif x.startswith("root//folly"): + return "buck2//folly/" + x.removeprefix("//") + return "buck2//" + x.removeprefix("//") + elif x.startswith("buck2//folly"): return x elif x.startswith("//fizz"): - return "root//" + x.removeprefix("//") + return "buck2//" + x.removeprefix("//") elif x.startswith("shim//"): return x else: @@ -445,7 +445,7 @@ def _fix_dep(x: str) -> [ def _fix_dep_in_string(x: str) -> str: """Replace internal labels in string values such as env-vars.""" return (x - .replace("//buck2/", "root//")) + .replace("//buck2/", "buck2//")) # Do a nasty conversion of e.g. ("supercaml", None, "ocaml-dev") to # 'fbcode//third-party-buck/platform010/build/supercaml:ocaml-dev'