Skip to content

Commit

Permalink
Fix documentation on docs.rs (#11)
Browse files Browse the repository at this point in the history
* Fix documentation on docs.rs

* Fix ci pipeline
  • Loading branch information
quambene authored Aug 7, 2024
1 parent c27a882 commit 211203b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions eric-bindings/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- changed
- removed

## v0.4.1 (2024-08-07)

- changed
- Fix publishing on docs.rs

## v0.4.0 (2024-08-07)

- added
Expand Down
16 changes: 11 additions & 5 deletions eric-bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eric-bindings"
version = "0.4.0"
version = "0.4.1"
authors.workspace = true
edition.workspace = true
readme.workspace = true
Expand All @@ -13,14 +13,20 @@ keywords = ["eric", "bindings", "taxes", "accounting"]
categories = ["external-ffi-bindings"]
build = "build.rs"

[lib]
path = "src/lib.rs"
name = "eric_bindings"

[package.metadata.docs.rs]
features = ["docs-rs"]

[features]
default = []
generate-bindings = ["dep:bindgen"]
# This feature is used in CI pipeline for unit tests.
no-linking = []

[lib]
path = "src/lib.rs"
name = "eric_bindings"
# This feature is used to publish the documentation for `eric-bindings`.
docs-rs = []

[dependencies]
anyhow = { workspace = true }
Expand Down
30 changes: 29 additions & 1 deletion eric-bindings/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@ pub fn main() -> io::Result<()> {
generate_bindings()?;

#[cfg(not(feature = "generate-bindings"))]
select_bindings()?;
{
#[cfg(not(feature = "docs-rs"))]
select_bindings()?;

#[cfg(feature = "docs-rs")]
select_bindings_for_docs_rs()?;
}

Ok(())
}

/// Select existing bindings
#[cfg(not(feature = "generate-bindings"))]
#[cfg(not(feature = "docs-rs"))]
fn select_bindings() -> io::Result<()> {
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").expect("Set by cargo");
let is_windows = std::env::var("CARGO_CFG_WINDOWS").is_ok();
Expand Down Expand Up @@ -126,3 +133,24 @@ fn generate_bindings() -> io::Result<()> {

Ok(())
}

/// Select latest bindings for documentation on docs.rs
#[cfg(feature = "docs-rs")]
fn select_bindings_for_docs_rs() -> io::Result<()> {
let bindings_file = "bindings_eric_40_1_8_0_linux_x86_64.rs";

let root_dir = std::env::var("CARGO_MANIFEST_DIR").expect("Set by cargo");
let bindings_path = Path::new(&root_dir).join("bindings").join(bindings_file);

let out_dir = env::var("OUT_DIR").expect("Can't read environment variable 'OUT_DIR'");
let bindings_target = PathBuf::from(out_dir).join("bindings.rs");

std::fs::copy(bindings_path.clone(), bindings_target.clone()).unwrap_or_else(|_| {
panic!(
"Can't copy file from {} to {}",
bindings_path.display(),
bindings_target.display(),
)
});
Ok(())
}
5 changes: 5 additions & 0 deletions eric-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- changed
- removed

## v0.3.1 (2024-08-07)

- changed
- Fix publishing on docs.rs

## v0.3.0 (2024-08-07)

- added
Expand Down
12 changes: 9 additions & 3 deletions eric-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eric-sdk"
version = "0.3.0"
version = "0.3.1"
authors.workspace = true
edition.workspace = true
readme.workspace = true
Expand All @@ -16,13 +16,19 @@ categories = ["finance"]
path = "src/lib.rs"
name = "eric_sdk"

[package.metadata.docs.rs]
features = ["docs-rs"]

[features]
default = []
no-linking = ["eric-bindings/no-linking"]
external-test = []
# This feature is used in CI pipeline for unit tests.
no-linking = ["eric-bindings/no-linking"]
# This feature is used to publish the documentation for `eric-sdk`.
docs-rs = ["eric-bindings/docs-rs"]

[dependencies]
eric-bindings = { version = "0.4.0", path = "../eric-bindings" }
eric-bindings = { version = "0.4.1", path = "../eric-bindings" }
anyhow = { workspace = true }

[dev-dependencies]
Expand Down

0 comments on commit 211203b

Please sign in to comment.