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

Fix crate build on docs.rs #281

Merged
merged 4 commits into from
Aug 24, 2022
Merged

Fix crate build on docs.rs #281

merged 4 commits into from
Aug 24, 2022

Conversation

rmanoka
Copy link
Contributor

@rmanoka rmanoka commented Jul 26, 2022

Use dynamic code-gen to build-around non-availabiltiy of some packages.

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

Use dynamic code-gen to build-around non-availabiltiy of some packages.
@rmanoka
Copy link
Contributor Author

rmanoka commented Jul 26, 2022

The documenation assumed GDAL 3.2 (the sys versions do not matter as cargo doc is cool enough to not link). With this PR, this is now the latest (3.5), and can be upgraded by changing gdal-sys/build.rs. Should be obvious to our-future-selves. 🤞

Use latest GDAL 3.5 pre-bindings for compiling for docs.
fn main() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");

// Hardcode a prebuilt binding version while generating docs.
// Otherwise docs.rs will explode due to not actually having libgdal installed.
if std::env::var("DOCS_RS").is_ok() {
let version = Version::parse("3.2.0").expect("invalid version for docs.rs");
let version = Version::parse("3.5.0").expect("invalid version for docs.rs");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: this seems a bit buried here, what about pulling the version out as global variables at the top, to make them easier to maintain as new versions are released?

At top:

// Set the following to the latest released version of GDAL for use by docs.rs
const DOCS_RS_GDAL_VERSION: &str = "3.5.0";
const DOCS_RS_GDAL_VERSION_NUM: &str = "3050000";

Here

let version = Version::parse(DOCS_RS_GDAL_VERSION).expect(...);
add_docs_rs_helper(Some(DOCS_RS_GDAL_VERSION_NUM));

Also - is there a way to programmatically derive the "3050000" value from "3.5.0", or does it vary somewhat independently? (presumably the major / minor parts of it follow the semver components). If the latter, might be good to include a comment on where to find this value; I didn't find it in the prebuilt bindings for 3.5, so it doesn't seem easily obvious for future versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The number is defined like so in gdal source:

/* GDAL_COMPUTE_VERSION macro introduced in GDAL 1.10 */
/* Must be used ONLY to compare with version numbers for GDAL >= 1.10 */
#ifndef GDAL_COMPUTE_VERSION
#define GDAL_COMPUTE_VERSION(maj,min,rev) ((maj)*1000000+(min)*10000+(rev)*100)
#endif

We'll probably refactor the version handling soon-ish as the recent gdal versions are not strictly semver (like 3.5.0.2). The semver crate seems to fail on these at present.

@spadarian
Copy link
Contributor

Do we still need

[package.metadata.docs.rs]
rustc-args = ["--cfg", "docsrs"]

in Cargo.toml?

@metasim
Copy link
Contributor

metasim commented Jul 28, 2022

Closes #268

@jdroenner jdroenner mentioned this pull request Aug 23, 2022
6 tasks
@jdroenner
Copy link
Member

can we merge this?

@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

I'm a bit behind on this, but do we know why the current approach isn't working? Was it a docs.rs bug?

@rmanoka
Copy link
Contributor Author

rmanoka commented Aug 23, 2022

@jdroenner Yes, we should merge this and closes PR #241 if it builds on docs.rs.
@lnicola quick summary: we rely on some cfg attributes to be set by docs.rs but they do not set it; they only set an env. var. afaiu. This PR gets around this by just using the env. variable directly. The cond. compiling was required to prevent compiler from trying to look for gdal on the docs.rs machine. Instead, we just dynamically create a wrapper function from the gdal-sys/build.rs that will either use libgdal to find the gdal version, or on docs.rs directly return the latest version that we've hardcoded.

I've checked this locally on the docs.rs docker images and it works.

@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

Did we try to ask someone working on docs.rs why the cfg is no longer set? I'm surprised there aren't more crates running into this, and the workaround is TBH quite complex.

@rmanoka
Copy link
Contributor Author

rmanoka commented Aug 23, 2022

Well it's been open for a while (ref. #268) and affects all crates depending on gdal. We could always un-complicate it if docs.rs supports a cfg attribute.

@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

Yeah, so I just re-discovered rust-lang/docs.rs#1580. We might be able to use https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#host-config instead, but it's probably not worth the hassle of an unstable option.

bors d+

@bors
Copy link
Contributor

bors bot commented Aug 23, 2022

✌️ rmanoka can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@rmanoka
Copy link
Contributor Author

rmanoka commented Aug 24, 2022

bors r+

@lnicola
Copy link
Member

lnicola commented Aug 24, 2022

rust-lang/docs.rs#1580 just got fixed though.

@bors
Copy link
Contributor

bors bot commented Aug 24, 2022

Build succeeded:

@bors bors bot merged commit 2093998 into master Aug 24, 2022
@rmanoka
Copy link
Contributor Author

rmanoka commented Aug 24, 2022

I'm fine with whatever gets docs compiling on publish.

@ChristianBeilschmidt ChristianBeilschmidt deleted the fix/docs-rs-build branch September 2, 2022 15:29
bors bot added a commit that referenced this pull request Sep 3, 2022
296: Increased documentation content of README and root rustdoc page. r=lnicola a=metasim

- [X] I agree to follow the project's [code of conduct](https://github.com/georust/gdal/blob/master/CODE_OF_CONDUCT.md).
- [X] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

I wanted to kickstart some work to level-up the documentation. Wanting to take an incremental approach, making it feel a bit less intimidating to make progress in the future. I don't see this as the only PR I do on this, just a start. All feedback welcome :). 

Related:
* #268
* #281

Co-authored-by: Simeon H.K. Fitch <fitch@astraea.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants