Skip to content

Commit 81d720a

Browse files
committed
workaround: libcdio ABI changes
1 parent f33640d commit 81d720a

File tree

6 files changed

+43
-12
lines changed

6 files changed

+43
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Apt Dependencies
4747
run: |
48-
sudo dpkg -i libcdio19t64_2.2.0-4_amd64.deb libcdio-dev_2.2.0-4_amd64.deb
48+
sudo apt-get install -y libcdio-dev
4949
5050
- name: Build
5151
run: |

libcdio-dev_2.2.0-4_amd64.deb

-174 KB
Binary file not shown.

libcdio19t64_2.2.0-4_amd64.deb

-59.8 KB
Binary file not shown.

riprip_core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ default-features = false
3737
[build-dependencies]
3838
dactyl = "0.10.*"
3939
oxford_join = "0.5.*"
40+
pkg-config = "0.3.*"
4041

4142
[build-dependencies.cdtoc]
4243
version = "0.8.*"

riprip_core/build.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ fn main() {
3737
println!("cargo:rerun-if-env-changed=CARGO_PKG_VERSION");
3838
println!("cargo:rerun-if-changed=skel");
3939

40+
// The `libcdio_sys` crate handles bindings to `libcdio`, but those
41+
// bindings unfortunately vary by version.
42+
let lib = match pkg_config::Config::new().atleast_version("2.1.0").probe("libcdio") {
43+
Ok(l) => l,
44+
Err(e) => panic!("{e}"),
45+
};
46+
let data =
47+
if lib.version.starts_with("2.1.") {
48+
"/// # `libcdio` True.
49+
const LIBCDIO_TRUE: u8 = 1;
50+
51+
/// # `libcdio` False.
52+
const LIBCDIO_FALSE: u8 = 0;"
53+
}
54+
else {
55+
"/// # `libcdio` True.
56+
const LIBCDIO_TRUE: bool = true;
57+
58+
/// # `libcdio` False.
59+
const LIBCDIO_FALSE: bool = false;"
60+
};
61+
File::create(out_path("libcdio-bools.rs"))
62+
.and_then(|mut f| f.write_all(data.as_bytes()).and_then(|_| f.flush()))
63+
.expect("Unable to save drive data.");
64+
4065
let raw = fetch_offsets();
4166
let offsets = parse_offsets(&raw);
4267
let caches = parse_caches(&offsets);

riprip_core/src/cdio.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ use std::{
5454

5555

5656

57+
// The bool types annoyingly changed between `2.1.x` and `2.2.x` so build.rs
58+
// generates `LIBCDIO_TRUE` and `LIBCDIO_FALSE` constants that we can use
59+
// instead, ensuring compatibility with both.
60+
include!(concat!(env!("OUT_DIR"), "/libcdio-bools.rs"));
61+
5762
/// # Cache Bust Timeout.
5863
const CACHE_BUST_TIMEOUT: Duration = Duration::from_secs(45);
5964

@@ -383,7 +388,7 @@ impl LibcdioInstance {
383388
// The return code is a bool, true for good, instead of the usual
384389
// 0 FFI normally kicks back.
385390
// Safety: this is an FFI call…
386-
if unsafe { libcdio_sys::cdio_get_hwinfo(self.as_ptr(), &mut raw) } {
391+
if LIBCDIO_TRUE == unsafe { libcdio_sys::cdio_get_hwinfo(self.as_ptr(), &mut raw) } {
387392
// Rather than deal with the uncertainty of pointers, let's recast
388393
// the signs since we have everything right here.
389394
let vendor_u8 = raw.psz_vendor.map(u8::saturating_from);
@@ -586,16 +591,16 @@ impl LibcdioInstance {
586591
self.as_ptr(),
587592
buf.as_mut_ptr().cast(),
588593
lsn,
589-
1, // Sector type: CDDA.
590-
false, // No random data manipulation thank you kindly.
591-
false, // No header syncing.
592-
0, // No headers.
593-
true, // YES audio block!
594-
false, // No EDC.
595-
u8::from(c2), // C2 or no C2?
596-
sub, // Subchannel? What kind?
597-
block_size, // Block size (varies by data requested).
598-
1, // Always read one block at a time.
594+
1, // Sector type: CDDA.
595+
LIBCDIO_FALSE, // No random data manipulation thank you kindly.
596+
LIBCDIO_FALSE, // No header syncing.
597+
0, // No headers.
598+
LIBCDIO_TRUE, // YES audio block!
599+
LIBCDIO_FALSE, // No EDC.
600+
u8::from(c2), // C2 or no C2?
601+
sub, // Subchannel? What kind?
602+
block_size, // Block size (varies by data requested).
603+
1, // Always read one block at a time.
599604
)
600605
};
601606

0 commit comments

Comments
 (0)