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

Lines changed: 17 additions & 14 deletions
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

Lines changed: 0 additions & 9 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 15 additions & 12 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 15 additions & 12 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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
)

0 commit comments

Comments
 (0)