Skip to content

Commit 1fb2b93

Browse files
authored
update buck2 samples using facebook/buck2#826 (#372)
- Use constraints to select action keys for tests on RE only - Use `--target-platforms` to select platform on the command line - Remove RE only attrs from targets
1 parent daa663e commit 1fb2b93

File tree

17 files changed

+70
-83
lines changed

17 files changed

+70
-83
lines changed

buck2/cpp/.buckconfig

+17-14
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@
1313
# limitations under the License.
1414

1515
[cells]
16-
root = .
17-
prelude = prelude
18-
toolchains = toolchains
19-
none = none
16+
root = .
17+
prelude = prelude
18+
toolchains = toolchains
19+
none = none
2020

2121
[cell_aliases]
22-
config = prelude
23-
ovr_config = prelude
24-
fbcode = none
25-
fbsource = none
26-
fbcode_macros = none
27-
buck = none
22+
config = prelude
23+
ovr_config = prelude
24+
fbcode = none
25+
fbsource = none
26+
fbcode_macros = none
27+
buck = none
2828

2929
# Uses a copy of the prelude bundled with the buck2 binary. You can alternatively delete this
3030
# section and vendor a copy of the prelude to the `prelude` directory of your project.
3131
[external_cells]
32-
prelude = bundled
32+
prelude = bundled
3333

3434
[parser]
35-
target_platform_detector_spec = target:root//...->prelude//platforms:default
35+
target_platform_detector_spec = target:root//...->root//platforms:remote_platform
3636

3737
[buck2]
3838
digest_algorithms = SHA256
@@ -44,7 +44,10 @@ cas_address = <CLUSTER_NAME>.cluster.engflow.com
4444
http_headers = <AUTH_HTTP_HEADERS>
4545

4646
[build]
47-
execution_platforms = root//platforms:remote_platform
47+
execution_platforms = root//platforms:remote_platform
4848

4949
[project]
50-
ignore = .git
50+
ignore = .git
51+
52+
[re]
53+
remote_execution_test_build_mode = root//platforms:remote_execution_action_keys

buck2/cpp/BUCK

-9
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@ cxx_binary(
1616
name = "main",
1717
srcs = ["main.cpp"],
1818
link_style = "static",
19-
exec_compatible_with = ["//platforms:remote_platform"],
20-
default_target_platform = "//platforms:remote_platform",
2119
)
2220

2321
cxx_binary(
2422
name = "cpp",
2523
srcs = ["main.cc"],
2624
deps = [":cpp_lib"],
27-
exec_compatible_with = ["//platforms:remote_platform"],
28-
default_target_platform = "//platforms:remote_platform",
2925
)
3026

3127
cxx_library(
@@ -35,8 +31,6 @@ cxx_library(
3531
],
3632
exported_headers = glob(["**/*.h"]),
3733
visibility = ["PUBLIC"],
38-
exec_compatible_with = ["//platforms:remote_platform"],
39-
default_target_platform = "//platforms:remote_platform",
4034
)
4135

4236
cxx_test(
@@ -45,7 +39,4 @@ cxx_test(
4539
deps = [
4640
":cpp_lib",
4741
],
48-
exec_compatible_with = ["//platforms:remote_platform"],
49-
default_target_platform = "//platforms:remote_platform",
50-
remote_execution_action_key_providers = "//platforms:remote_execution_action_keys",
5142
)

buck2/cpp/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ Clone the repository and replace the relevant configs in `.buckconfig`.
4949
Build the example:
5050

5151
```
52-
buck2 build //:cpp_lib
52+
buck2 build --remote-only //:cpp_lib
5353
```
5454

5555
Test the example:
5656

5757
```
58-
buck2 test //:cpp_test
58+
buck2 test --remote-only //:cpp_test
5959
```

buck2/golang/.buckconfig

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
[cells]
2-
root = .
3-
prelude = prelude
4-
toolchains = toolchains
5-
none = none
2+
root = .
3+
prelude = prelude
4+
toolchains = toolchains
5+
none = none
66

77
[cell_aliases]
8-
config = prelude
9-
fbcode = none
10-
fbsource = none
11-
buck = none
8+
config = prelude
9+
fbcode = none
10+
fbsource = none
11+
buck = none
1212

1313
[external_cells]
14-
prelude = bundled
14+
prelude = bundled
1515

1616
[parser]
17-
target_platform_detector_spec = target:root//...->prelude//platforms:default
17+
target_platform_detector_spec = target:root//...->root//platforms:remote_platform
1818

1919
[buck2]
2020
digest_algorithms = SHA256
@@ -26,7 +26,10 @@ cas_address = <CLUSTER_NAME>.cluster.engflow.com
2626
http_headers = <AUTH_HTTP_HEADERS>
2727

2828
[build]
29-
execution_platforms = root//platforms:remote_platform
29+
execution_platforms = root//platforms:remote_platform
3030

3131
[project]
32-
ignore = .git
32+
ignore = .git
33+
34+
[re]
35+
remote_execution_test_build_mode = root//platforms:remote_execution_action_keys

buck2/golang/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ It is based on three existing samples in the Buck2 upstream repo and the EngFlow
1313
In the `platforms` cell we specify:
1414
* The platform used for remote execution in this project `root//platforms:remote_platform`, which includes the definition of the Docker image used for remote execution, and that defines constraints for targets to run in the remote execution environment. This platform provides an `ExecutionPlatformRegistrationInfo`.
1515
* The action keys `root//platforms:remote_execution_action_keys`, which provides a default `BuildModeInfo` that is needed for RE of tests to function properly.
16-
* The platform `image` configured in `platforms/defs.bzl`, notably, uses a different image than other Buck2 samples in this repo. Specifically, it uses a public AWS image that has `go` preinstalled. This is because, unlike Bazel go rules, Buck2 go rules do not include a hermetic go binary.
16+
* The platform `image` configured in `platforms/defs.bzl`, notably, uses a different image than other Buck2 samples in this repo. Specifically, it uses a public AWS image that has `go` preinstalled. This is because, unlike Bazel go rules, Buck2 go rules do not include a hermetic go binary. Image details can be found in https://gallery.ecr.aws/docker/library/golang. he Dockerfile can be found in https://github.com/docker-library/golang/blob/master/1.23/bookworm/Dockerfile.
1717

1818
In the `toolchains` cell we specify:
1919

@@ -27,13 +27,13 @@ The `main` cell and `library` cell:
2727
To test this cell with RE run (after setting up `.buckconfig` as indicated below):
2828

2929
```
30-
buck2 test //go/greeting:greeting_test
30+
buck2 test --remote-only //go/greeting:greeting_test
3131
```
3232

3333
You can also build the `main` for this sample by running:
3434

3535
```
36-
buck2 build //go:hello
36+
buck2 build --remote-only //go:hello
3737
```
3838

3939
### Relevant configs in `.buckconfig`

buck2/golang/go/greeting/BUCK

-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ go_library(
2121
go_test(
2222
name = "greeting_test",
2323
srcs = glob(["*.go"]),
24-
remote_execution_action_key_providers = "//platforms:remote_execution_action_keys",
2524
)

buck2/golang/platforms/defs.bzl

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def _platforms(ctx):
2525

2626
# A bookworm image with go pre-installed.
2727
# Unlike Bazel go_toolchain, Buck2 go_toolchain does not include a hermetic go binary. Image details can be found in https://gallery.ecr.aws/docker/library/golang.
28+
# The Dockerfile can be found in https://github.com/docker-library/golang/blob/master/1.23/bookworm/Dockerfile.
2829
image = "docker://public.ecr.aws/docker/library/golang:1.23.3-bookworm@sha256:3f3b9daa3de608f3e869cd2ff8baf21555cf0fca9fd34251b8f340f9b7c30ec5"
2930
name = ctx.label.raw_target()
3031
platform = ExecutionPlatformInfo(
@@ -46,6 +47,7 @@ def _platforms(ctx):
4647
return [
4748
DefaultInfo(),
4849
ExecutionPlatformRegistrationInfo(platforms = [platform]),
50+
PlatformInfo(label = str(name), configuration = configuration),
4951
]
5052

5153
def _action_keys(ctx):
@@ -55,7 +57,7 @@ def _action_keys(ctx):
5557
]
5658

5759
platforms = rule(
58-
attrs = {},
60+
attrs = {},
5961
impl = _platforms
6062
)
6163

buck2/python/.buckconfig

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
[cells]
2-
root = .
3-
prelude = prelude
4-
toolchains = toolchains
5-
none = none
2+
root = .
3+
prelude = prelude
4+
toolchains = toolchains
5+
none = none
66

77
[cell_aliases]
8-
config = prelude
9-
fbcode = none
10-
fbsource = none
11-
buck = none
8+
config = prelude
9+
fbcode = none
10+
fbsource = none
11+
buck = none
1212

1313
[external_cells]
14-
prelude = bundled
14+
prelude = bundled
1515

1616
[parser]
17-
target_platform_detector_spec = target:root//...->prelude//platforms:default
17+
target_platform_detector_spec = target:root//...->root//platforms:remote_platform
1818

1919
[buck2]
2020
digest_algorithms = SHA256
@@ -26,7 +26,10 @@ cas_address = <CLUSTER_NAME>.cluster.engflow.com
2626
http_headers = <AUTH_HTTP_HEADERS>
2727

2828
[build]
29-
execution_platforms = root//platforms:remote_platform
29+
execution_platforms = root//platforms:remote_platform
3030

3131
[project]
32-
ignore = .git
32+
ignore = .git
33+
34+
[re]
35+
remote_execution_test_build_mode = root//platforms:remote_execution_action_keys

buck2/python/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The `main` cell and `library` cell:
2626
To test these cells with RE run (after setting up `.buckconfig` as indicated below):
2727

2828
```
29-
buck2 build //main:check_main
29+
buck2 build --remote-only //main:check_main
3030
```
3131

3232
The `hello` cell:
@@ -36,7 +36,7 @@ The `hello` cell:
3636
To test this cell with RE run (after setting up `.buckconfig` as indicated below):
3737

3838
```
39-
buck2 test //hello:hello_unittest_test
39+
buck2 test --remote-only //hello:hello_unittest_test
4040
```
4141

4242
### Relevant configs in `.buckconfig`

buck2/python/hello/BUCK

-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ python_test(
3030
name = "hello_unittest_test",
3131
srcs = ["hello_unittest_test.py"],
3232
deps = [":hellolib"],
33-
remote_execution_action_key_providers = "//platforms:remote_execution_action_keys",
3433
)

buck2/python/platforms/defs.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def _platforms(ctx):
4545
return [
4646
DefaultInfo(),
4747
ExecutionPlatformRegistrationInfo(platforms = [platform]),
48+
PlatformInfo(label = str(name), configuration = configuration),
4849
]
4950

5051
def _action_keys(ctx):
@@ -54,7 +55,7 @@ def _action_keys(ctx):
5455
]
5556

5657
platforms = rule(
57-
attrs = {},
58+
attrs = {},
5859
impl = _platforms
5960
)
6061

buck2/rust/.buckconfig

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ execution_platforms = root//platforms:remote_platform
3030

3131
[project]
3232
ignore = .git
33+
34+
[re]
35+
remote_execution_test_build_mode = root//platforms:remote_execution_action_keys

buck2/rust/BUCK

-5
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,4 @@ rust_test(
3434
["test/**/*.rs"],
3535
),
3636
deps = [":library"],
37-
# TODO: remove these once https://github.com/facebook/buck2/pull/826 gets merged.
38-
remote_execution_action_key_providers = select({
39-
"//platforms:engflow": "//platforms:remote_execution_action_keys",
40-
"DEFAULT": None,
41-
}),
4237
)

buck2/rust/platforms/BUCK

-10
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,11 @@
1515
load(":defs.bzl", "platforms")
1616
load(":defs.bzl", "action_keys")
1717

18-
constraint_setting(
19-
name = "re_provider"
20-
)
21-
22-
constraint_value(
23-
name = "engflow",
24-
constraint_setting = ":re_provider",
25-
)
26-
2718
# This platform configures details of remote execution.
2819
platforms(
2920
name = "remote_platform",
3021
cpu_configuration = "config//cpu:x86_64",
3122
os_configuration = "config//os:linux",
32-
re_provider = ":engflow",
3323
)
3424

3525
# This action_key provides a default BuildModeInfo that is needed for RE of tests to function properly.

buck2/rust/platforms/defs.bzl

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def _platforms(ctx):
2020
constraints = dict()
2121
constraints.update(ctx.attrs.cpu_configuration[ConfigurationInfo].constraints)
2222
constraints.update(ctx.attrs.os_configuration[ConfigurationInfo].constraints)
23-
constraints.update(ctx.attrs.re_provider[ConfigurationInfo].constraints)
2423
configuration = ConfigurationInfo(
2524
constraints = constraints,
2625
values = {},
@@ -63,7 +62,6 @@ platforms = rule(
6362
attrs = {
6463
"cpu_configuration": attrs.dep(providers = [ConfigurationInfo]),
6564
"os_configuration": attrs.dep(providers = [ConfigurationInfo]),
66-
"re_provider": attrs.dep(providers = [ConfigurationInfo]),
6765
},
6866
impl = _platforms
6967
)

infra/setup-buck2.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22
set -xe
33

4-
# Get the Buck2 binary - pinned to https://github.com/facebook/buck2/releases/tag/2024-12-16
5-
curl -L -O https://github.com/facebook/buck2/releases/download/2024-12-16/buck2-x86_64-unknown-linux-musl.zst
4+
# Get the Buck2 binary - pinned to https://github.com/facebook/buck2/releases/tag/2024-03-01
5+
curl -L -O https://github.com/facebook/buck2/releases/download/2025-03-01/buck2-x86_64-unknown-linux-musl.zst
66

77
# Unpack the binary.
88
unzstd buck2-x86_64-unknown-linux-musl.zst

infra/test-buck2.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ alias buck2="$(realpath buck2-exe)"
66

77
# Run cpp example
88
cd buck2/cpp
9-
buck2 build //:cpp_lib
10-
buck2 test //:cpp_test
9+
buck2 build --remote-only //:cpp_lib
10+
buck2 test --remote-only //:cpp_test
1111
cd ..
1212

1313
# Run python example
1414
cd python
15-
buck2 build //main:check_main
16-
buck2 test //hello:hello_unittest_test
15+
buck2 build --remote-only //main:check_main
16+
buck2 test --remote-only //hello:hello_unittest_test
1717
cd ..
1818

1919
# Run go example
2020
cd golang
21-
buck2 build //go:hello
22-
buck2 test //go/greeting:greeting_test
21+
buck2 build --remote-only //go:hello
22+
buck2 test --remote-only //go/greeting:greeting_test
2323
cd ..
2424

2525
# Run rust example

0 commit comments

Comments
 (0)