-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Rust] flatc build script wrapper #6453
Conversation
Co-authored-by: Geordon Worley <vadixidav@gmail.com>
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
/// [google/flatbuffers.git]: https://github.com/google/flatbuffers | ||
const FLATBUFFERS_COMMIT_SHA: &str = env!("FLATBUFFERS_COMMIT_SHA"); | ||
|
||
/// The location of the copy of the `flatc` executable compiled by this crate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already are aiming at unifying versions across languages, so packaging flatc can be a nice feautre to have.
const FLATC_EXECUTABLE: &str = concat!(env!("OUT_DIR"), "/bin/flatc"); | ||
|
||
/// An internal error that occured. | ||
struct Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using this_error to ease the boilerplate
@@ -1,16 +1,19 @@ | |||
extern crate flatbuffers; | |||
|
|||
#[allow(dead_code, unused_imports)] | |||
#[path = "../../include_test/include_test1_generated.rs"] | |||
pub mod include_test1_generated; | |||
pub mod include_test1_generated { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using tests/rust_usage_test/outdir/
as a regression test for build.rs support, please extend that for your tests. I'm not sure if we should promote this over the #[path = ... ]
approach just yet since that is a breaking change.
Also, the way imports and stuff work may be affected by the solution to #5589 in breaking ways too, and I'd like to minimize the amount of sequential breakage. (btw, if you have suggestions, please comment on that issue)
@@ -46,6 +57,15 @@ rustup component add clippy | |||
cargo clippy $TARGET_FLAG | |||
check_test_result "No Cargo clippy lints test" | |||
|
|||
cargo test $TARGET_FLAG -- --quiet --test build_script_wrapper | |||
TEST_RESULT=$? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the check_test_result function
@@ -0,0 +1,279 @@ | |||
/* | |||
* Copyright 2018 Google Inc. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2021
|
||
fn main() { | ||
let git_sha = if let Ok(output) = Command::new("git") | ||
.args(&["rev-parse", "--short=7", "HEAD"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to make it short imo
fn try_compile(&self) -> Result<(), Error> { | ||
let output_path = self.output_path.as_ref().map_or_else( | ||
|| env::var("OUT_DIR").unwrap(), | ||
|path| format!("{}", path.display()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be done in new
. the None
variant isn't actually used
fn build_script_wrapper() { | ||
let output = Path::new(&env::var("OUT_DIR").unwrap()).join("monster_generated.rs"); | ||
|
||
let src = fs::read_to_string(&output).expect("Failed to read generated code"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might want to test that at least some known symbols/substrings are in there
rust/flatc/src/lib.rs
Outdated
|
||
impl Build { | ||
#[doc(hidden)] | ||
pub fn output<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this used?
Thank you for the review. This PR is mostly just what was written here: https://github.com/rjsberry/flatbuffers/tree/rust/flatc. I applied some changes on top of that and added myself to the commit as a co author. I will be adding a few more commits to help me get it working for my use case specifically first. After that, I will address the things in the review. I will circle back around to make broad improvements on this PR before fully opening it up. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
I ran into an issue where this intersected with my day job and it is going to take a long time to get legal to give me the okay because they are so slow. Therefore, I am going to have to pull out of this effort. Anyone feel free to rebase my branch and make the above fixed, and I would greatly appreciate it. |
This is for #5216. Currently a draft PR just for review purposes.