From c55a7b6bde2f4abe15ab760c27aec1d1a8bdda62 Mon Sep 17 00:00:00 2001 From: vmagro Date: Fri, 4 Oct 2024 18:23:59 -0700 Subject: [PATCH] nativelink cloud --- .buckconfig | 14 +++++++++++++ .github/workflows/ci.yml | 11 +++++++--- platforms/BUCK | 26 ++++++++++++++++++++++++ platforms/defs.bzl | 44 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 platforms/BUCK create mode 100644 platforms/defs.bzl diff --git a/.buckconfig b/.buckconfig index 379b397f8ce..0eb68be3a82 100644 --- a/.buckconfig +++ b/.buckconfig @@ -23,5 +23,19 @@ [buck2] file_watcher = watchman + materializations = deferred + sqlite_materializer_state = true + defer_write_actions = true + hash_all_commands = true + +[buck2_re_client] + action_cache_address = grpcs://cas-vmagro.build-faster.nativelink.net + engine_address = grpcs://cas-vmagro.build-faster.nativelink.net + cas_address = grpcs://cas-vmagro.build-faster.nativelink.net + http_headers = x-nativelink-api-key: $NATIVELINK_CLOUD_API_KEY + instance_name = vmagro + +[build] + execution_platforms = antlir//platforms:exec-platforms diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 782b75e7dbd..f3b4ee67818 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,13 +7,14 @@ defaults: jobs: test: - runs-on: + #runs-on: # this runner comes with 150GB of disk space - labels: 4-core-ubuntu + #labels: 4-core-ubuntu steps: - uses: actions/checkout@v4 with: submodules: true + - uses: facebook/install-dotslash@latest - uses: dtolnay/rust-toolchain@stable with: @@ -25,7 +26,7 @@ jobs: mkfs.btrfs ${{ runner.temp }}/image.btrfs sudo mount ${{ runner.temp }}/image.btrfs antlir2-out sudo chown -R $(id -u):$(id -g) antlir2-out - - name: Install deps + - name: Install system deps run: | sudo apt install \ cpio jq libcap-dev systemd-container @@ -38,6 +39,10 @@ jobs: - name: Test target graph run: | ./buck2 bxl //ci:test_target_graph.bxl:test_target_graph + # This secret must be attached to the first buck invocation + env: + NATIVELINK_CLOUD_API_KEY: ${{ secrets.NATIVELINK_CLOUD_API_KEY }} + - name: Find tests run: | diff --git a/platforms/BUCK b/platforms/BUCK new file mode 100644 index 00000000000..c32c75f92ab --- /dev/null +++ b/platforms/BUCK @@ -0,0 +1,26 @@ +load("@prelude//:rules.bzl", "platform") +load("@prelude//platforms:defs.bzl", "execution_platform", "host_configuration") +load(":defs.bzl", "nativelink_platform", "exec_platforms") + +nativelink_platform( + name = "nativelink", + cpu_configuration = "config//cpu:x86_64", + os_configuration = "config//os:linux", + visibility = ["PUBLIC"], +) + +execution_platform( + name = "host", + cpu_configuration = host_configuration.cpu, + os_configuration = host_configuration.os, + use_windows_path_separators = host_info().os.is_windows, + visibility = ["PUBLIC"], +) + +exec_platforms( + name = "exec-platforms", + platforms = [ + ":nativelink", + ":host", + ] +) diff --git a/platforms/defs.bzl b/platforms/defs.bzl new file mode 100644 index 00000000000..beadb8fda07 --- /dev/null +++ b/platforms/defs.bzl @@ -0,0 +1,44 @@ +def _nativelink_platform(ctx): + constraints = {} + constraints.update(ctx.attrs.cpu_configuration[ConfigurationInfo].constraints) + constraints.update(ctx.attrs.os_configuration[ConfigurationInfo].constraints) + + configuration = ConfigurationInfo( + constraints = constraints, + values = {}, + ) + + platform = ExecutionPlatformInfo( + label = ctx.label.raw_target(), + configuration = configuration, + executor_config = CommandExecutorConfig( + local_enabled = True, + remote_enabled = True, + use_limited_hybrid = True, + remote_execution_properties = { + # "arch": ctx.attrs.cpu_configuration.label.name, + # "os": ctx.attrs.os_configuration.label.name, + }, + remote_execution_use_case = "antlir", + remote_output_paths = "output_paths", + ), + ) + + return [DefaultInfo(), platform] + +nativelink_platform = rule(attrs = { + "cpu_configuration": attrs.dep(providers = [ConfigurationInfo]), + "os_configuration": attrs.dep(providers = [ConfigurationInfo]), +}, impl = _nativelink_platform) + +def _exec_platforms(ctx): + return [ + DefaultInfo(), + ExecutionPlatformRegistrationInfo( + platforms = [p[ExecutionPlatformInfo] for p in ctx.attrs.platforms], + ), + ] + +exec_platforms = rule(attrs = { + "platforms": attrs.list(attrs.dep(providers = [ExecutionPlatformInfo])), +}, impl = _exec_platforms)