Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

vadixidav
Copy link

This is for #5216. Currently a draft PR just for review purposes.

Co-authored-by: Geordon Worley <vadixidav@gmail.com>
@google-cla
Copy link

google-cla bot commented Feb 8, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the idea of packaging flatc with this crate... I wonder if we can use it to couple the flatbuffers library with the flatc version somehow.

Related: #6149

@krojew might have opinions on this

Copy link
Contributor

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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=$?
Copy link
Collaborator

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.
Copy link
Collaborator

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"])
Copy link
Collaborator

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()),
Copy link
Collaborator

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");
Copy link
Collaborator

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


impl Build {
#[doc(hidden)]
pub fn output<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used?

@vadixidav
Copy link
Author

vadixidav commented Feb 9, 2021

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.

@google-cla
Copy link

google-cla bot commented Feb 9, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@vadixidav
Copy link
Author

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.

@vadixidav vadixidav closed this Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants