-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor: Use links, Error types and group code
#9
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,50 @@ | ||
| use std::env; | ||
| use std::error::Error; | ||
| use std::path::PathBuf; | ||
|
|
||
| // libcdio uses a homegrown boolean type for versions < 2.1.1. | ||
| // The homegrown boolean type is not recognized by bindgen. | ||
| // This would result in different code gen for versions < 2.1.1 and versions >= 2.1.1. | ||
| // To prevent this, we include stdbool.h ourselves, which suppresses the homegrown boolean type. | ||
| const CDIO_HEADER: &str = "#include <stdbool.h> | ||
| #include <cdio/cdio.h> | ||
| #include <cdio/cd_types.h> | ||
| #include <cdio/logging.h> | ||
| #include <cdio/mmc_cmds.h> | ||
| #include <cdio/utf8.h>\n"; | ||
| fn main() -> Result<(), Box<dyn Error>> { | ||
| system_deps::Config::new().probe()?; | ||
| make_bindings()?; | ||
|
|
||
| #[cfg(feature = "iso9660")] | ||
| const ISO9660_HEADER: &str = "#include <cdio/iso9660.h>\n"; | ||
|
|
||
| #[cfg(feature = "udf")] | ||
| const UDF_HEADER: &str = "#include <cdio/udf.h>\n"; | ||
|
|
||
| #[cfg(feature = "cdda")] | ||
| const CDDA_HEADER: &str = "#include <cdio/paranoia/cdda.h>\n"; | ||
|
|
||
| #[cfg(feature = "paranoia")] | ||
| const PARANOIA_HEADER: &str = "#include <cdio/paranoia/paranoia.h>\n"; | ||
|
|
||
| const HEADERS: &[&str] = &[ | ||
| CDIO_HEADER, | ||
| #[cfg(feature = "iso9660")] | ||
| ISO9660_HEADER, | ||
| #[cfg(feature = "udf")] | ||
| UDF_HEADER, | ||
| #[cfg(feature = "cdda")] | ||
| CDDA_HEADER, | ||
| #[cfg(feature = "paranoia")] | ||
| PARANOIA_HEADER, | ||
| ]; | ||
|
|
||
| fn main() { | ||
| if let Err(s) = system_deps::Config::new().probe() { | ||
| println!("cargo:warning={s}"); | ||
| std::process::exit(1); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| let headers = HEADERS.join(""); | ||
| fn make_bindings() -> Result<(), Box<dyn Error>> { | ||
| // libcdio uses a homegrown boolean type for versions < 2.1.1. | ||
| // The homegrown boolean type is not recognized by bindgen. | ||
| // This would result in different code gen for versions < 2.1.1 and versions >= 2.1.1. | ||
| // To prevent this, we include stdbool.h ourselves, which suppresses the homegrown boolean type. | ||
| static CDIO_HEADERS: &str = r" | ||
| #include <stdbool.h> | ||
| #include <cdio/cdio.h> | ||
| #include <cdio/cd_types.h> | ||
| #include <cdio/logging.h> | ||
| #include <cdio/mmc_cmds.h> | ||
| #include <cdio/utf8.h> | ||
| "; | ||
| static HEADERS: &[&str] = &[ | ||
| CDIO_HEADERS, | ||
| #[cfg(feature = "iso9660")] | ||
| "#include <cdio/iso9660.h>", | ||
| #[cfg(feature = "udf")] | ||
| "#include <cdio/udf.h>", | ||
| #[cfg(feature = "cdda")] | ||
| "#include <cdio/paranoia/cdda.h>", | ||
| #[cfg(feature = "paranoia")] | ||
| "#include <cdio/paranoia/paranoia.h>", | ||
| ]; | ||
| let headers = HEADERS.join("\n"); | ||
| let bindings = bindgen::Builder::default() | ||
| .header_contents("wrapper.h", &headers) | ||
| .allowlist_file(r".*[/\\]cdio[/\\][^/\\]*\.h") | ||
| .allowlist_file(r".*[/\\]cdio[/\\]paranoia[/\\][^/\\]*\.h") | ||
| .wrap_unsafe_ops(true) | ||
| .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) | ||
| .generate() | ||
| .expect("Unable to generate bindings"); | ||
| .generate()?; | ||
|
|
||
| let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
| let out_path = | ||
| PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR should have been set by Cargo")); | ||
| bindings.write_to_file(out_path.join("bindings.rs"))?; | ||
|
|
||
| bindings | ||
| .write_to_file(out_path.join("bindings.rs")) | ||
| .expect("Couldn't write bindings!"); | ||
| Ok(()) | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.