[pyth_oracle] Improve build.rs robustness and expose types.#343
Merged
[pyth_oracle] Improve build.rs robustness and expose types.#343
Conversation
jayantk
previously approved these changes
Apr 6, 2023
| println!("cargo:rustc-link-search=./program/c/target"); | ||
| // Cargo exposes ENV variables for feature flags that can be used to determine whether to do a | ||
| // self-contained build that compiles the C components automatically. | ||
| if std::env::var("CARGO_FEATURE_LIBRARY").is_ok() { |
Contributor
There was a problem hiding this comment.
is there any reason not to do this for both build paths? this seems like a great simplification of the current build process.
Contributor
Author
There was a problem hiding this comment.
No reason, this is the correct way to do it. But I wasn't sure how many things would break and this was a safe small PR to get a review on. I can make it the default and check anywhere that might break / has been relying on relative paths. I just didn't plan to do it in this PR.
Contributor
There was a problem hiding this comment.
Let's get this merged and I can make it the default
guibescos
approved these changes
Apr 10, 2023
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a feature flag,
libraryto thepyth-oracleprogram. When toggled on, the library exposes its account types for use as a library instead of a standalone program. When the flag is enabled, thebuild.rsscript will also switch to execute the C compilation as well. The artefacts are output within the Rust target sandbox rather than into the relative source directory (./program/c/target).The benefit of this:
Rather than fully switch to this, the feature flag is added so any existing reliance on the current build method continues to work. The primary reason I wanted this is because I am relying on
pyth-sdk-rsand I found it very hard to tell exactly what is different there versus the accounts defined within the contract. With this feature flag it is possible for me to enforce extra constraints inpyth-sdk-rsthat prevent the libraries going out of sync and highlights the differences in a testable way.See the associated PR for context.