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

Build refactoring - cbindgen #313

Merged
merged 14 commits into from
Feb 23, 2024
Merged

Build refactoring - cbindgen #313

merged 14 commits into from
Feb 23, 2024

Conversation

r1viollet
Copy link
Contributor

@r1viollet r1viollet commented Feb 13, 2024

What does this PR do?

Ensure cbindgen is included in the package's build steps. By removing logics from the shell scripts, we can make build steps more modular.
This is step 1 of moving towards a common "feature" driven build system.

Motivation

You can refer to the RFC around features

Additional Notes

Anything else we should know when reviewing?

How to test the change?

Describe here in detail how the change can be validated.

For Reviewers

  • If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

@r1viollet r1viollet requested review from a team as code owners February 13, 2024 09:54
@r1viollet r1viollet marked this pull request as draft February 13, 2024 09:54
@github-actions github-actions bot added profiling Relates to the profiling* modules. ci-build telemetry common labels Feb 13, 2024
@r1viollet r1viollet force-pushed the r1viollet/cbindgen_in_packages branch 2 times, most recently from c7ee4cc to 02f1292 Compare February 13, 2024 10:10
@r1viollet r1viollet force-pushed the r1viollet/cbindgen_in_packages branch 2 times, most recently from 2a26f0c to 4b991c5 Compare February 13, 2024 12:56
Ensure cbindgen is included in the package's build steps.
The motivation is to remove logic from the shell scripts.
@r1viollet r1viollet force-pushed the r1viollet/cbindgen_in_packages branch from 4b991c5 to 72533ef Compare February 13, 2024 13:31
@r1viollet r1viollet marked this pull request as ready for review February 13, 2024 14:01
Comment on lines 10 to 15
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let header_name = "common.h";
let output_base_dir = env::var("DESTDIR").ok(); // Use `ok()` to convert Result to Option

generate_header(crate_dir, header_name, output_base_dir.as_deref());
println!("cargo:rerun-if-env-changed=DESTDIR");
Copy link
Contributor

Choose a reason for hiding this comment

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

We have the exact same code for all three crates, with the only difference being the header name. Maybe worth factoring into a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have mixed feelings about hiding some of this behaviour :-)
I added the magical function all the same.

cargo_target_path.join("include/datadog/").join(header_name)
} else {
// If relative, adjust the path accordingly. we are in a crate, so get back to top level
let adjusted_path = Path::new("..").join(cargo_target_path);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this guaranteed to work? What if the command is run deeper in the crate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No.
However I can not think of a way to magically infer where the headers should be placed.
I looked into using the OUT_DIR variable, but that also has different depths depending on build parameters.
So I think this being not perfect still guarantees that it works in the use cases we have today.
Happy to reconsider if you find a different logic that works well.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we want the root of the workspace, can we try https://doc.rust-lang.org/cargo/commands/cargo-locate-project.html#options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is a new iteration using your proposal.

…ibdatadog into r1viollet/cbindgen_in_packages
Add a function to read configuration from env vars
and calls into the header generation functions.
When DESTDIR is set, ensure we use the cargo target path to compute absolute paths.
…ative paths

Use the locate-project feature to find the root of the project.

/// Configure the header generation using environment variables.
/// call into `generate_header` with the appropriate arguments.
///
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can still find ways to break this, but I feel we already improve the state of the build.

@danielsn danielsn merged commit 6544c25 into main Feb 23, 2024
20 checks passed
@danielsn danielsn deleted the r1viollet/cbindgen_in_packages branch February 23, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-build common profiling Relates to the profiling* modules. telemetry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants