-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build oak_proto_rust for bare metal with Bazel.
BUG: 340185565 Change-Id: Iae5cef128b32e549a50991764fdb6fa60e2a2f92
- Loading branch information
Showing
25 changed files
with
4,636 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,5 +64,6 @@ cargo_build_script( | |
], | ||
deps = [ | ||
"//micro_rpc_build", | ||
"//oak_proto_build_utils", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
# This package provides build utils for protos. At the moment this is only | ||
# used from Bazel therefore not present in Cargo workspaces. | ||
|
||
load("@rules_rust//rust:defs.bzl", "rust_library") | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
licenses = ["notice"], | ||
) | ||
|
||
rust_library( | ||
name = "oak_proto_build_utils", | ||
srcs = glob(["src/**"]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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. | ||
|
||
use std::fs; | ||
|
||
/// Replaces refs to prost with prost_derive. See b/340185847. | ||
/// Only to be called from build scripts of crates that generate prost code. | ||
/// Only to be called when building with Bazel. | ||
/// The issue that this fixes is that prost with "derive" feature uses | ||
/// "prost-derive", which requires std. In Cargo, that works OK as the | ||
/// feature "std" isn't propagated to deps of crates that don't use them, | ||
/// but Bazel's can't handle that. With Bazel, if we bring prost-derive | ||
/// into the index, it'll make deps like `bytes` also use the "std" feature. | ||
/// Take into account that in Cargo, features of dependencies are declared in | ||
/// the "depending" crate, that is, they belong to the dependency arc, while | ||
/// in Bazel, one crate is brought into an index with a fixed set of features. | ||
/// To solve this, and to be able to build for bare metal from Bazel, we | ||
/// import prost without derive to oak_no_std_crates_index, use prost-derive | ||
/// derive macro directly, but we need to change the crate name, as we no | ||
/// longer have prost re-exporting the derive macros. | ||
pub fn fix_prost_derives() -> Result<(), Box<dyn std::error::Error>> { | ||
// let out_dir_path = std::path::PathBuf::from(std::env::var("OUT_DIR"))?; | ||
|
||
let out_dir = std::env::var("OUT_DIR")?; | ||
for entry in fs::read_dir(&out_dir)? { | ||
let file_path = entry?.path(); | ||
let contents = fs::read_to_string(&file_path)?; | ||
|
||
let updated = contents.replace("::prost::Message", "::prost_derive::Message"); | ||
let updated = updated.replace("::prost::Oneof", "::prost_derive::Oneof"); | ||
let updated = updated.replace("::prost::Enumeration", "::prost_derive::Enumeration"); | ||
|
||
fs::write(&file_path, updated)?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
# Upstream prost-types depends on prost-derive unconditionally, which means | ||
# we can't use it in our oak_no_std_crates_index. | ||
|
||
load("@rules_rust//rust:defs.bzl", "rust_library") | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
rust_library( | ||
name = "prost-types", | ||
srcs = glob(["src/**"]), | ||
proc_macro_deps = [ | ||
"@oak_crates_index//:prost-derive", | ||
], | ||
deps = select({ | ||
"@platforms//os:none": [ | ||
"@oak_no_std_crates_index//:prost", | ||
], | ||
"//conditions:default": [ | ||
"@oak_crates_index//:prost", | ||
], | ||
}), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "prost-types" | ||
version = "0.12.6" | ||
authors = [ | ||
"Dan Burkert <[email protected]>", | ||
"Lucio Franco <[email protected]>", | ||
"Casper Meijn <[email protected]>", | ||
"Tokio Contributors <[email protected]>", | ||
] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/tokio-rs/prost" | ||
documentation = "https://docs.rs/prost-types" | ||
readme = "README.md" | ||
description = "Prost definitions of Protocol Buffers well known types." | ||
edition = "2021" | ||
rust-version = "1.70" | ||
|
||
[lib] | ||
doctest = false | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["prost/std"] | ||
|
||
[dependencies] | ||
prost = { version = "0.12.6", path = "../prost", default-features = false, features = ["prost-derive"] } | ||
|
||
[dev-dependencies] | ||
proptest = "1" |
Oops, something went wrong.