From ae50d2d76132ec5f6f2ae8f983ad5b7016672149 Mon Sep 17 00:00:00 2001 From: Tiziano Santoro Date: Wed, 3 Jul 2024 15:16:00 +0000 Subject: [PATCH] Bazelify crates Bug: 349587436 Bug: 349587509 Change-Id: I7cbede8c6e2854c8628075d3367481a164b7f50b --- bazel/crates/oak_crates_index.bzl | 6 +++ cargo-bazel-lock.json | 8 +++- oak_containers_agent/BUILD | 66 +++++++++++++++++++++++++++++++ oak_hello_world_linux_init/BUILD | 36 +++++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 oak_containers_agent/BUILD create mode 100644 oak_hello_world_linux_init/BUILD diff --git a/bazel/crates/oak_crates_index.bzl b/bazel/crates/oak_crates_index.bzl index 99eafbd54eb..dbadb94c70d 100644 --- a/bazel/crates/oak_crates_index.bzl +++ b/bazel/crates/oak_crates_index.bzl @@ -54,6 +54,10 @@ def oak_crates_index(cargo_lockfile, lockfile): version = "*", deps = ["@jemalloc"], )], + # Enable `tokio_unstable` so that we can access the Tokio runtime metrics. + "tokio": [crate.annotation( + rustc_flags = ["--cfg=tokio_unstable"], + )], }, cargo_lockfile = cargo_lockfile, # In Cargo-free mode this is used as output, not input. lockfile = lockfile, # Shares most contents with cargo_lockfile. @@ -373,9 +377,11 @@ def oak_crates_index(cargo_lockfile, lockfile): "net", "parking_lot", "process", + "rt", "rt-multi-thread", "signal", "sync", + "time", ], version = "*", ), diff --git a/cargo-bazel-lock.json b/cargo-bazel-lock.json index 7503b19c3ee..acd55571a63 100644 --- a/cargo-bazel-lock.json +++ b/cargo-bazel-lock.json @@ -1,5 +1,5 @@ { - "checksum": "c4be2749e541c67a98fce81c31388468fc37a4113e0abc002e9ba5f8d661f680", + "checksum": "29000e1cc506207f10f6725fdfd827400c9e64d2df09af5681b12f77c9a8413b", "crates": { "acpi 5.0.0": { "name": "acpi", @@ -23877,6 +23877,12 @@ ], "selects": {} }, + "rustc_flags": { + "common": [ + "--cfg=tokio_unstable" + ], + "selects": {} + }, "version": "1.37.0" }, "license": "MIT", diff --git a/oak_containers_agent/BUILD b/oak_containers_agent/BUILD new file mode 100644 index 00000000000..285185713aa --- /dev/null +++ b/oak_containers_agent/BUILD @@ -0,0 +1,66 @@ +# +# Copyright 2024 The Project Oak Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") + +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +exports_files(["README.md"]) + +rust_library( + name = "lib", + srcs = glob( + ["src/**"], + exclude = ["src/main.rs"], + ), + compile_data = [":README.md"], + crate_name = "oak_containers_agent", + deps = [ + "@oak_crates_index//:anyhow", + "@oak_crates_index//:http", + "@oak_crates_index//:nix", + "@oak_crates_index//:opentelemetry", + "@oak_crates_index//:opentelemetry-otlp", + "@oak_crates_index//:opentelemetry_sdk", + "@oak_crates_index//:procfs", + "@oak_crates_index//:tokio", + "@oak_crates_index//:tokio-stream", + "@oak_crates_index//:tonic", + "@oak_crates_index//:tower", + ], +) + +rust_binary( + name = "oak_containers_agent", + srcs = ["src/main.rs"], + compile_data = [":README.md"], + deps = [ + ":lib", + "@oak_crates_index//:anyhow", + "@oak_crates_index//:clap", + "@oak_crates_index//:http", + "@oak_crates_index//:nix", + "@oak_crates_index//:opentelemetry", + "@oak_crates_index//:opentelemetry-otlp", + "@oak_crates_index//:opentelemetry_sdk", + "@oak_crates_index//:procfs", + "@oak_crates_index//:tokio", + "@oak_crates_index//:tower", + ], +) diff --git a/oak_hello_world_linux_init/BUILD b/oak_hello_world_linux_init/BUILD new file mode 100644 index 00000000000..ea1e34dc1b9 --- /dev/null +++ b/oak_hello_world_linux_init/BUILD @@ -0,0 +1,36 @@ +# +# Copyright 2024 The Project Oak Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +load("@rules_rust//rust:defs.bzl", "rust_binary") + +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +exports_files(["README.md"]) + +rust_binary( + name = "oak_hello_world_linux_init", + srcs = glob(["src/**"]), + compile_data = [":README.md"], + deps = [ + "@oak_crates_index//:anyhow", + "@oak_crates_index//:log", + "@oak_crates_index//:nix", + "@oak_crates_index//:simple_logger", + ], +)