Skip to content

Commit 5f3b9be

Browse files
author
Adam Singer
committed
Add no_prelude remote execution to github actions
Enabling testing of remote execution on github actions for `no_prelude` * Create github action that generates .buckconfig.local using `NATIVELINK_HEADER_RW_KEY` from gha secrets. * Set `container-image` used for remote execution specific to setup of buck2. * Update .gitignore to include .buckconfig.local. * Include a `platforms` configuration for the `no_prelude` example. * Update `go_toolchain.bzl` to be remote enabled friendly, no need to download a toolchain when remote worker has one. Open question: * Was the downloading of go toolchain to be remote execution compatible prior to this change?
1 parent 749c7ea commit 5f3b9be

File tree

7 files changed

+89
-13
lines changed

7 files changed

+89
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: build_example_nativelink_no_prelude
2+
inputs:
3+
NATIVELINK_HEADER_RW_KEY_SECRET:
4+
description: ''
5+
required: true
6+
runs:
7+
using: composite
8+
steps:
9+
- name: Build example/no_prelude directory using remote execution
10+
run: |-
11+
{
12+
echo "[buck2_re_client]
13+
engine_address = grpc://scheduler-buck2.build-faster.nativelink.net:443
14+
action_cache_address = grpc://cas-buck2.build-faster.nativelink.net:443
15+
cas_address = grpc://cas-buck2.build-faster.nativelink.net:443
16+
http_headers = x-nativelink-api-key:$NATIVELINK_HEADER_RW_KEY
17+
tls = true
18+
instance_name = main
19+
enabled = true
20+
[build]
21+
execution_platforms = root//platforms:platforms"
22+
} > examples/no_prelude/.buckconfig.local
23+
cd examples/no_prelude
24+
$RUNNER_TEMP/artifacts/buck2 build //...
25+
env:
26+
NATIVELINK_HEADER_RW_KEY: ${{ inputs.NATIVELINK_HEADER_RW_KEY_SECRET }}
27+
shell: bash

.github/workflows/build-and-test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
$RUNNER_TEMP/artifacts/buck2 build //... -v 2
4949
$RUNNER_TEMP/artifacts/buck2 test //... -v 2
5050
- uses: ./.github/actions/build_example_no_prelude
51+
- uses: ./.github/actions/build_example_nativelink_no_prelude
52+
with:
53+
NATIVELINK_HEADER_RW_KEY_SECRET: ${{ secrets.NATIVELINK_HEADER_RW_KEY_SECRET }}
5154
- uses: ./.github/actions/setup_reindeer
5255
- uses: ./.github/actions/build_bootstrap
5356
linux-build-examples:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Cargo.lock
33
buck-out
44
/.direnv
5+
.buckconfig.local
56

67
# symlinks
78
/examples/with_prelude/prelude

examples/no_prelude/go/rules.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def _go_binary_impl(ctx: AnalysisContext) -> list[Provider]:
1414

1515
cmd = cmd_args([ctx.attrs.toolchain[GoCompilerInfo].compiler_path, "build", "-o", out.as_output()] + sources)
1616

17-
ctx.actions.run(cmd, category = "compile")
17+
ctx.actions.run(cmd, env = {"GOCACHE":ctx.attrs.toolchain[GoCompilerInfo].GOCACHE}, category = "compile")
1818

1919
return [
2020
DefaultInfo(default_output = out),

examples/no_prelude/platforms/BUCK

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
load(":defs.bzl", "platforms")
2+
3+
platforms(name = "platforms")
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under both the MIT license found in the
4+
# LICENSE-MIT file in the root directory of this source tree and the Apache
5+
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
6+
# of this source tree.
7+
8+
def _platforms(ctx):
9+
configuration = ConfigurationInfo(
10+
constraints = {},
11+
values = {},
12+
)
13+
14+
platform = ExecutionPlatformInfo(
15+
label = ctx.label.raw_target(),
16+
configuration = configuration,
17+
executor_config = CommandExecutorConfig(
18+
local_enabled = True,
19+
remote_enabled = True,
20+
use_limited_hybrid = True,
21+
# Set those up based on what workers you've registered with NativeLink.
22+
remote_execution_properties = {
23+
"OSFamily": "linux",
24+
"container-image": "docker://buck2-github:latest",
25+
},
26+
remote_execution_use_case = "buck2-default",
27+
remote_output_paths = "output_paths",
28+
),
29+
)
30+
31+
return [DefaultInfo(), ExecutionPlatformRegistrationInfo(platforms = [platform])]
32+
33+
platforms = rule(attrs = {}, impl = _platforms)

examples/no_prelude/toolchains/go_toolchain.bzl

+21-12
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,33 @@
77

88
GoCompilerInfo = provider(
99
doc = "Information about how to invoke the go compiler.",
10-
fields = ["compiler_path", "GOROOT"],
10+
fields = ["compiler_path", "GOROOT", "GOCACHE"],
1111
)
1212

13+
def is_remote_enabled() -> bool:
14+
re_enabled = read_root_config("buck2_re_client", "enabled", "false")
15+
return re_enabled == "true"
16+
1317
def _go_toolchain_impl(ctx):
14-
download = _download_toolchain(ctx)
18+
is_re_enabled = is_remote_enabled()
19+
gocache="/tmp/gocache"
20+
if is_re_enabled:
21+
return [DefaultInfo(), GoCompilerInfo(compiler_path = "go", GOROOT = "", GOCACHE=gocache)]
22+
else:
23+
download = _download_toolchain(ctx)
1524

16-
compiler_dst = ctx.actions.declare_output("compiler.exe" if host_info().os.is_windows else "compiler")
25+
compiler_dst = ctx.actions.declare_output("compiler.exe" if host_info().os.is_windows else "compiler")
1726

18-
cmd = cmd_args()
19-
if host_info().os.is_windows:
20-
compiler_src = cmd_args(download, format = "{}\\go\\bin\\go.exe", relative_to = (compiler_dst, 1))
21-
cmd.add([ctx.attrs._symlink_bat, compiler_dst.as_output(), compiler_src])
22-
else:
23-
compiler_src = cmd_args(download, format = "{}/go/bin/go", relative_to = (compiler_dst, 1))
24-
cmd.add(["ln", "-sf", compiler_src, compiler_dst.as_output()])
27+
cmd = cmd_args()
28+
if host_info().os.is_windows:
29+
compiler_src = cmd_args(download, format = "{}\\go\\bin\\go.exe", relative_to = (compiler_dst, 1))
30+
cmd.add([ctx.attrs._symlink_bat, compiler_dst.as_output(), compiler_src])
31+
else:
32+
compiler_src = cmd_args(download, format = "{}/go/bin/go", relative_to = (compiler_dst, 1))
33+
cmd.add(["ln", "-sf", compiler_src, compiler_dst.as_output()])
2534

26-
ctx.actions.run(cmd, category = "cp_compiler")
27-
return [DefaultInfo(default_output = download), GoCompilerInfo(compiler_path = compiler_dst, GOROOT = "")]
35+
ctx.actions.run(cmd, category = "cp_compiler")
36+
return [DefaultInfo(default_output = download), GoCompilerInfo(compiler_path = compiler_dst, GOROOT = "", GOCACHE=gocache)]
2837

2938
go_toolchain = rule(
3039
impl = _go_toolchain_impl,

0 commit comments

Comments
 (0)