georust / proj

Rust bindings for the latest stable release of PROJ
https://docs.rs/proj
Apache License 2.0
137 stars 45 forks source link

manually specify existing proj installation via env variables #78

Open michaelkirk opened 3 years ago

michaelkirk commented 3 years ago

For most people, pkg-config is a great option. But for when it's not, I think conventions exist for manually specifying environment variables.

Something like:

PROJ_SYS_PROJ_INCLUDE_DIR=/path/to/my/proj/include PROJ_SYS_LIBRARY_PATH=/path/to/my/proj/lib cargo build

We don't currently support this, but we should.

michaelkirk commented 3 years ago

Though it's not "official", I often refer to https://kornel.ski/rust-sys-crate for guidance with how to do sys crates right.

Relevant section:

Finally, support overriding library location with _PATH or _LIB_DIR environmental variable (example). This is necessary in some cases, such as cross-compilation and custom builds of the library (e.g. with custom features enabled, or if the library installed in /lib is 6 years old).

Which links to this example: https://github.com/kornelski/rust-lcms2-sys/blob/bed8356d67ff21fd0476ce2045ad410272ab553a/src/build.rs#L16-L26

  if let Ok(include_dir) = env::var("LCMS2_INCLUDE_DIR") {
        println!("cargo:include={}", include_dir);
    }

    if let Some(lib_dir) = env::var_os("LCMS2_LIB_DIR") {
        let lib_dir = Path::new(&lib_dir);
        let dylib_name = format!("{}lcms2{}", consts::DLL_PREFIX, consts::DLL_SUFFIX);
        if lib_dir.join(dylib_name).exists() ||
           lib_dir.join("liblcms2.a").exists() ||
           lib_dir.join("lcms2.lib").exists() {
            println!("cargo:rustc-link-search=native={}", lib_dir.display());
            println!("cargo:rustc-link-lib=lcms2");
            return;
        }
    }

so, using LCMS2_INCLUDE_DIR, LCMS2_LIB_DIR openssl agrees (https://docs.rs/openssl/0.10.32/openssl/). using OPENSSL_LIB_DIR and OPENSSL_INCLUDE_DIR.

llvm-sys goes a different route, using LLVM_SYS_<VERSION>_PREFIX, which seems nice, but is less common: https://gitlab.com/taricorp/llvm-sys.rs/-/blob/master/build.rs

Seems like there's not a complete consensus, but I'd vote for: PROJ_LIB_DIR and PROJ_INCLUDE_DIR