### Get Server Capabilities Source: https://context7.com/bazelbuild/remote-apis/llms.txt Shows how to create a Capabilities client and retrieve server capabilities, including cache and execution details, and API version compatibility. ```go import repb "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2" // Create Capabilities client capClient := repb.NewCapabilitiesClient(conn) // Get server capabilities capRequest := &repb.GetCapabilitiesRequest{ InstanceName: "default", } caps, err := capClient.GetCapabilities(ctx, capRequest) if err != nil { log.Fatalf("Failed to get capabilities: %v", err) } // Check cache capabilities if caps.CacheCapabilities != nil { fmt.Printf("Digest function: %v\n", caps.CacheCapabilities.DigestFunctions) fmt.Printf("Action cache update: %v\n", caps.CacheCapabilities.ActionCacheUpdateCapabilities) fmt.Printf("Max batch size: %d bytes\n", caps.CacheCapabilities.MaxBatchTotalSizeBytes) for _, compressor := range caps.CacheCapabilities.SupportedCompressors { fmt.Printf("Supported compressor: %v\n", compressor) } } // Check execution capabilities if caps.ExecutionCapabilities != nil { fmt.Printf("Exec enabled: %v\n", caps.ExecutionCapabilities.ExecEnabled) fmt.Printf("Digest function: %v\n", caps.ExecutionCapabilities.DigestFunction) if caps.ExecutionCapabilities.ExecutionPriorityCapabilities != nil { prio := caps.ExecutionCapabilities.ExecutionPriorityCapabilities fmt.Printf("Priority range: %d to %d\n", prio.Priorities[0].MinPriority, prio.Priorities[0].MaxPriority) } } // Check API version compatibility if caps.LowApiVersion != nil { fmt.Printf("Low API version: %d.%d.%d\n", caps.LowApiVersion.Major, caps.LowApiVersion.Minor, caps.LowApiVersion.Patch) } if caps.HighApiVersion != nil { fmt.Printf("High API version: %d.%d.%d\n", caps.HighApiVersion.Major, caps.HighApiVersion.Minor, caps.HighApiVersion.Patch) } ``` -------------------------------- ### Platform Proto with arm-a32 ISA and extensions Source: https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/execution/v2/platform.md Example of a Platform proto specifying the arm-a32 instruction set architecture with ARMv7 and ARM VFPv4 extensions. ```json { "properties": [ { "name": "ISA", "value": "arm-a32" }, { "name": "ISA", "value": "armv7" }, { "name": "ISA", "value": "arm-vfpv4" } ] } ``` -------------------------------- ### Platform Proto with arm-a64 ISA and extensions Source: https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/execution/v2/platform.md Example of a Platform proto specifying the arm-a64 instruction set architecture with ARMv8 and ARM SVE extensions. ```json { "properties": [ { "name": "ISA", "value": "arm-a64" }, { "name": "ISA", "value": "armv8" }, { "name": "ISA", "value": "arm-sve" } ] } ``` -------------------------------- ### Platform Proto with x86-64 ISA Source: https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/execution/v2/platform.md Example of a Platform proto specifying the x86-64 instruction set architecture. ```json { "properties": [ { "name": "ISA", "value": "x86-64" }, { "name": "ISA", "value": "x86-avx2" } ] } ``` -------------------------------- ### Get Remote APIs Go Package Source: https://github.com/bazelbuild/remote-apis/blob/main/README.md Use this command to fetch the generated Go code for interacting with the API via gRPC. This is for non-Bazel build systems. ```bash go get github.com/bazelbuild/remote-apis ``` -------------------------------- ### Import Remote APIs Go Package Source: https://github.com/bazelbuild/remote-apis/blob/main/README.md Example of how to import the generated Go code for the remote execution API v2. Ensure the path is correct for your project structure. ```go repb "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2" ``` -------------------------------- ### Manage Blobs with Content Addressable Storage (CAS) API Source: https://context7.com/bazelbuild/remote-apis/llms.txt Provides operations for uploading, checking existence, and downloading blobs using the CAS API. Requires a gRPC connection and appropriate client setup. ```go import repb "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2" // Create CAS client casClient := repb.NewContentAddressableStorageClient(conn) // Upload blobs to CAS using BatchUpdateBlobs uploadRequest := &repb.BatchUpdateBlobsRequest{ InstanceName: "default", Requests: []*repb.BatchUpdateBlobsRequest_Request{ { Digest: &repb.Digest{ Hash: computeSHA256(sourceCode), SizeBytes: int64(len(sourceCode)), }, Data: sourceCode, }, { Digest: &repb.Digest{ Hash: computeSHA256(buildScript), SizeBytes: int64(len(buildScript)), }, Data: buildScript, }, }, } uploadResp, err := casClient.BatchUpdateBlobs(ctx, uploadRequest) if err != nil { log.Fatalf("Upload failed: %v", err) } // Check which blobs already exist using FindMissingBlobs findRequest := &repb.FindMissingBlobsRequest{ InstanceName: "default", BlobDigests: []*repb.Digest{ {Hash: "abc123...", SizeBytes: 1024}, {Hash: "def456...", SizeBytes: 2048}, }, } findResp, err := casClient.FindMissingBlobs(ctx, findRequest) // findResp.MissingBlobDigests contains only blobs not in CAS // Download blobs from CAS downloadRequest := &repb.BatchReadBlobsRequest{ InstanceName: "default", Digests: []*repb.Digest{ {Hash: "abc123...", SizeBytes: 1024}, }, } downloadResp, err := casClient.BatchReadBlobs(ctx, downloadRequest) for _, resp := range downloadResp.Responses { if resp.Status.Code == int32(codes.OK) { fmt.Printf("Downloaded %d bytes\n", len(resp.Data)) } } ``` -------------------------------- ### Create and Use Action Cache Client in Go Source: https://context7.com/bazelbuild/remote-apis/llms.txt Demonstrates how to create an Action Cache client and perform cache lookups and updates. Ensure the connection is established before creating the client. ```go import repb "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2" // Create Action Cache client acClient := repb.NewActionCacheClient(conn) // Look up cached result for an action getRequest := &repb.GetActionResultRequest{ InstanceName: "default", ActionDigest: &repb.Digest{ Hash: "action-sha256-hash", SizeBytes: 512, }, InlineStdout: true, // Include stdout in response InlineStderr: true, // Include stderr in response } result, err := acClient.GetActionResult(ctx, getRequest) if err == nil { // Cache hit - use cached result fmt.Printf("Cached exit code: %d\n", result.ExitCode) fmt.Printf("Stdout: %s\n", string(result.StdoutRaw)) for _, file := range result.OutputFiles { fmt.Printf("Output: %s (digest: %s)\n", file.Path, file.Digest.Hash) } } else if status.Code(err) == codes.NotFound { // Cache miss - need to execute action fmt.Println("Action not cached, executing...") } // Store action result in cache after execution updateRequest := &repb.UpdateActionResultRequest{ InstanceName: "default", ActionDigest: actionDigest, ActionResult: &repb.ActionResult{ ExitCode: 0, StdoutRaw: []byte("Build successful"), StderrRaw: []byte(""), OutputFiles: []*repb.OutputFile{ { Path: "output/binary", Digest: &repb.Digest{ Hash: "binary-sha256-hash", SizeBytes: 10240, }, IsExecutable: true, }, }, ExecutionMetadata: &repb.ExecutedActionMetadata{ Worker: "worker-01", ExecutionStartTimestamp: timestamppb.Now(), ExecutionCompletedTimestamp: timestamppb.Now(), }, }, } cachedResult, err := acClient.UpdateActionResult(ctx, updateRequest) ``` -------------------------------- ### Create and Use Log Stream Client Source: https://context7.com/bazelbuild/remote-apis/llms.txt Demonstrates how to create a LogStream client, create a new log stream for an action, write data to it using the ByteStream API, and read log output. ```go import logstreampb "github.com/bazelbuild/remote-apis/build/bazel/remote/logstream/v1" // Create LogStream client logClient := logstreampb.NewLogStreamServiceClient(conn) // Create a new log stream for an action createRequest := &logstreampb.CreateLogStreamRequest{ Parent: "operations/action-operation-name", LogStream: &logstreampb.LogStream{ // Name is assigned by server }, } logStream, err := logClient.CreateLogStream(ctx, createRequest) if err != nil { log.Fatalf("Failed to create log stream: %v", err) } fmt.Printf("Created log stream: %s\n", logStream.Name) fmt.Printf("Write resource name: %s\n", logStream.WriteResourceName) // Write to the log stream (typically done by the worker) // Using ByteStream API with the WriteResourceName byteStreamClient := bytestreampb.NewByteStreamClient(conn) writeStream, err := byteStreamClient.Write(ctx) if err != nil { log.Fatalf("Failed to open write stream: %v", err) } // Send log data in chunks writeStream.Send(&bytestreampb.WriteRequest{ ResourceName: logStream.WriteResourceName, WriteOffset: 0, Data: []byte("Compiling source.cc...\n"), FinishWrite: false, }) writeStream.Send(&bytestreampb.WriteRequest{ ResourceName: logStream.WriteResourceName, WriteOffset: 24, Data: []byte("Build complete.\n"), FinishWrite: true, }) // Read from log stream (client monitoring execution) readRequest := &bytestreampb.ReadRequest{ ResourceName: logStream.Name, ReadOffset: 0, ReadLimit: 0, // No limit } readStream, err := byteStreamClient.Read(ctx, readRequest) for { resp, err := readStream.Recv() if err == io.EOF { break } fmt.Print(string(resp.Data)) } ``` -------------------------------- ### Push Remote Asset Mapping in Go Source: https://context7.com/bazelbuild/remote-apis/llms.txt Illustrates how to use the Push client to register an asset mapping with the server, associating URIs and qualifiers with a content digest. ```go import assetpb "github.com/bazelbuild/remote-apis/build/bazel/remote/asset/v1" import repb "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2" // Create Push client to register assets pushClient := assetpb.NewPushClient(conn) // Push an asset mapping to the server pushRequest := &assetpb.PushBlobRequest{ InstanceName: "default", Uris: []string{ "https://example.com/library-1.2.3.jar", }, Qualifiers: []*assetpb.Qualifier{ {Name: "checksum.sha256", Value: "known-sha256-hash"}, }, BlobDigest: &repb.Digest{ Hash: "cas-digest-hash", SizeBytes: 5242880, }, } pushResp, err := pushClient.PushBlob(ctx, pushRequest) ``` -------------------------------- ### Build Remote Execution Proto Files Source: https://github.com/bazelbuild/remote-apis/blob/main/CONTRIBUTING.md Run this command to ensure the proto files build correctly before submitting substantive changes. This is a prerequisite for contributing. ```bash bazel build build/bazel/remote/execution/v2:remote_execution_proto ``` -------------------------------- ### Fetch Remote Asset Blob in Go Source: https://context7.com/bazelbuild/remote-apis/llms.txt Shows how to use the Fetch client to retrieve a remote asset by URI, with optional qualifiers for verification. Handles potential fetch errors. ```go import assetpb "github.com/bazelbuild/remote-apis/build/bazel/remote/asset/v1" // Create Fetch client fetchClient := assetpb.NewFetchClient(conn) // Fetch a remote asset by URI fetchRequest := &assetpb.FetchBlobRequest{ InstanceName: "default", Uris: []string{ "https://github.com/example/repo/archive/v1.0.0.tar.gz", }, Qualifiers: []*assetpb.Qualifier{ {Name: "checksum.sha256", Value: "expected-sha256-hash"}, }, } fetchResp, err := fetchClient.FetchBlob(ctx, fetchRequest) if err != nil { log.Fatalf("Fetch failed: %v", err) } fmt.Printf("Fetched blob digest: %s\n", fetchResp.BlobDigest.Hash) fmt.Printf("Resolved URI: %s\n", fetchResp.Uri) ``` -------------------------------- ### Fetch Remote Asset Directory in Go Source: https://context7.com/bazelbuild/remote-apis/llms.txt Demonstrates fetching a remote directory, such as a Git repository, using the Fetch client. The response contains a digest pointing to the directory tree in CAS. ```go import assetpb "github.com/bazelbuild/remote-apis/build/bazel/remote/asset/v1" // Fetch a directory (e.g., git repository) fetchDirRequest := &assetpb.FetchDirectoryRequest{ InstanceName: "default", Uris: []string{ "https://github.com/example/repo.git", }, Qualifiers: []*assetpb.Qualifier{ {Name: "vcs.branch", Value: "main"}, {Name: "vcs.commit", Value: "abc123def456"}, }, } fetchDirResp, err := fetchClient.FetchDirectory(ctx, fetchDirRequest) // fetchDirResp.RootDirectoryDigest points to the directory tree in CAS ``` -------------------------------- ### Enable Git Hooks for Proto Generation Source: https://github.com/bazelbuild/remote-apis/blob/main/README.md Configure Git to automatically run hooks from the specified directory. This ensures Go proto code is generated on commit. ```bash git config core.hooksPath hooks/ ``` -------------------------------- ### Bazel Remote Execution Configuration Source: https://context7.com/bazelbuild/remote-apis/llms.txt Provides sample .bazelrc configurations for enabling remote execution and caching, including settings for executor, cache, instance name, authentication, and performance tuning. ```bash # .bazelrc configuration for remote execution # Remote execution backend build:remote --remote_executor=grpcs://remote-execution.example.com:443 # Remote caching only (no execution) build:cache --remote_cache=grpcs://cache.example.com:443 # Instance name (namespace for the remote service) build:remote --remote_instance_name=my-project # Authentication build:remote --google_default_credentials # Or with explicit credentials build:remote --remote_header=Authorization=Bearer $(cat /path/to/token) # Performance tuning build:remote --remote_timeout=3600 build:remote --remote_retries=5 build:remote --jobs=500 # BES (Build Event Service) for build results build:remote --bes_backend=grpcs://bes.example.com:443 build:remote --bes_results_url=https://results.example.com/invocations/ # Platform configuration for remote workers build:remote --extra_execution_platforms=//platforms:linux_x86_64 build:remote --host_platform=//platforms:linux_x86_64 # Download outputs selectively build:remote --remote_download_minimal ``` -------------------------------- ### Connect and Execute Action with Remote Execution API Source: https://context7.com/bazelbuild/remote-apis/llms.txt Connects to a Remote Execution server and executes a specified action. Handles monitoring of the operation's progress and retrieves results. ```go import ( repb "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2" "google.golang.org/grpc" ) // Connect to a Remote Execution server conn, err := grpc.Dial("remote-execution.example.com:443", grpc.WithTransportCredentials(creds)) if err != nil { log.Fatalf("Failed to connect: %v", err) } deferr conn.Close() // Create execution client execClient := repb.NewExecutionClient(conn) // Define the action to execute action := &repb.Action{ CommandDigest: &repb.Digest{ Hash: "abc123...", // SHA256 hash of the Command proto SizeBytes: 256, }, InputRootDigest: &repb.Digest{ Hash: "def456...", // SHA256 hash of the input directory tree SizeBytes: 4096, }, Timeout: durationpb.New(300 * time.Second), } // Execute the action remotely request := &repb.ExecuteRequest{ InstanceName: "default", ActionDigest: actionDigest, // Digest of the serialized Action SkipCacheLookup: false, // Check action cache first } // Execute returns a stream of Operation responses stream, err := execClient.Execute(ctx, request) if err != nil { log.Fatalf("Execute failed: %v", err) } // Monitor execution progress for { op, err := stream.Recv() if err == io.EOF { break } if op.Done { var response repb.ExecuteResponse op.Response.UnmarshalTo(&response) fmt.Printf("Exit code: %d\n", response.Result.ExitCode) fmt.Printf("Stdout digest: %s\n", response.Result.StdoutDigest.Hash) } } ``` -------------------------------- ### Specify Resource Type Qualifier Source: https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/asset/v1/qualifiers.md Use the 'resource_type' qualifier to describe the type of resource. For file assets, use an existing media type. For Git repositories, use 'application/x-git'. ```json { "uris": [ "https://github.com/bazelbuild/remote-apis.git" ], "qualifiers": [ { "name": "resource_type", "value": "application/x-git" } ] } ``` -------------------------------- ### Define Execution Platform in Bazel Source: https://context7.com/bazelbuild/remote-apis/llms.txt Define an execution platform with specific constraint values and execution properties. This is used to specify the environment where build actions should run. ```bazel platform( name = "linux_x86_64", constraint_values = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], exec_properties = { "OSFamily": "Linux", "container-image": "docker://gcr.io/my-project/build-image:latest", "Pool": "default", }, ) ``` -------------------------------- ### Use Remote Execution in Bazel Source: https://context7.com/bazelbuild/remote-apis/llms.txt Configure a Bazel target to be compatible with a specific execution platform. This ensures the build action runs in the defined environment when remote execution is enabled. ```bazel cc_binary( name = "my_app", srcs = ["main.cc"], exec_compatible_with = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], ) ``` -------------------------------- ### Specify Directory Qualifier Source: https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/asset/v1/qualifiers.md Use the 'directory' qualifier to specify the relative path of a subdirectory within the resource. Ensure there is no trailing slash. ```json { "uris": [ "https://github.com/bazelbuild/remote-apis.git" ], "qualifiers": [ { "name": "directory", "value": "build/bazel/remote/execution/v2" } ] } ``` -------------------------------- ### Specify Subresource Integrity Checksum Source: https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/asset/v1/qualifiers.md Use the 'checksum.sri' qualifier to provide a Subresource Integrity checksum of the content. Multiple checksums can be specified, separated by whitespace. The server validates at least one. ```json { "uris": [ "https://github.com/bazelbuild/remote-apis/archive/v2.0.0.tar.gz" ], "qualifiers": [ { "name": "checksum.sri", "value": "sha384-G9d9sKLNRfeFfGn1mnVXeJzXSbkCsYt11kl5hJnHpdzfVuLIuruIDnrs/lZyB4Gs" } ] } ``` -------------------------------- ### Specify VCS Branch Qualifier Source: https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/asset/v1/qualifiers.md Use the 'vcs.branch' qualifier to specify the name of the branch under source control management. ```json { "uris": [ "https://github.com/bazelbuild/remote-apis.git" ], "qualifiers": [ { "name": "vcs.branch", "value": "master" } ] } ``` -------------------------------- ### Specify VCS Commit Qualifier Source: https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/asset/v1/qualifiers.md Use the 'vcs.commit' qualifier to specify the identity of a specific version of the content under source control management, such as a Git commit-ish or Subversion revision. ```json { "uris": [ "https://github.com/bazelbuild/remote-apis.git" ], "qualifiers": [ { "name": "vcs.commit", "value": "b5123b1bb2853393c7b9aa43236db924d7e32d61" } ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.