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

manually specify existing proj installation via env variables #78

Open
michaelkirk opened this issue Feb 21, 2021 · 1 comment
Open

Comments

@michaelkirk
Copy link
Member

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
Copy link
Member Author

michaelkirk commented Feb 21, 2021

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 <LIBRARY_NAME>_PATH or <LIBRARY_NAME>_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

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

No branches or pull requests

1 participant