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

Environment variable to identify the library name #11966

Open
azam opened this issue Apr 12, 2023 · 6 comments
Open

Environment variable to identify the library name #11966

azam opened this issue Apr 12, 2023 · 6 comments
Labels
A-environment-variables Area: environment variables C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@azam
Copy link

azam commented Apr 12, 2023

Problem

Cargo allows for building libraries having different name than the crate name (name field on [package]) via the name field on [lib], such as given the following manifest, crate name will be goodname but built library will be named libothername.so or so.

[packege]
name = "goodname"
version = "0.1.0"
edition = "2021"

[lib]
name = "othername"
crate-type = ["cdylib"]

For binaries, we have CARGO_BIN_NAME being populated with similar target name for binary on tests etc, but we do not have the equivalent of it for libraries, thus my request is to have CARGO_LIB_NAME, or any suitable variable name that will be populated with the target library name, having same behavior as CARGO_BIN_NAME.

Proposed Solution

Add an env var CARGO_LIB_NAME to be populated with the value set on name field on [lib], if set or default to package name.

Notes

Ref:

@azam azam added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Apr 12, 2023
@epage
Copy link
Contributor

epage commented Apr 12, 2023

Could you expand on your use case for a CARGO_LIB_NAME?

@azam
Copy link
Author

azam commented Apr 12, 2023

For my specific use case, I am using pgx to create a Postgres extension, and currently it uses the package name to get to the compiled target library file to copy to Postgres directories in order to load it for tests. Since library name can be different than the crate name, currently it cannot find the renamed library as it is trying to match to package name.

See here

@epage
Copy link
Contributor

epage commented Apr 12, 2023

So more specifically, you are needing a way for a test target to find the lib target's file name?

How would CARGO_LIB_NAME fit into that as it would only be set within the lib target?

FYI Integration tests have access to CARGO_BIN_EXE_<name> in case knowing of that precedent is useful

@azam
Copy link
Author

azam commented Apr 12, 2023

Yes, that would be correct.

pgx test framework gets the compiled binary from the build directory, strips the lib prefix, so that it matches Postgres extension name conventions, matches extensions to the architecture and copies over the compiled library to Postgres. Currently CARGO_PKG_NAME is used with the assumption that library name is the same as package name. Having the library name exposed as an env var would be helpful in knowing the target file without parsing the whole cargo manifest.

CARGO_BIN_EXE_<name> would be useful if we are to find for executable binaries, but this is the case for library, where there can only be one library for a package, unlike binaries.

@epage
Copy link
Contributor

epage commented Apr 12, 2023

My calling out of CARGO_BIN_EXE_<name> was more so to serve as an example of behavior you might more closely want, a CARBO_LIB_PATH or something.

@azam
Copy link
Author

azam commented Apr 12, 2023

Oh, got it. CARGO_LIB_PATH as suggested, might be as useful as well. My request for just the library name on CARGO_LIB_NAME is because it was sufficient for my use case, and also it would be on feature parity with CARGO_BIN_NAME.

@weihanglo weihanglo added A-environment-variables Area: environment variables S-needs-team-input Status: Needs input from team on whether/how to proceed. labels Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-environment-variables Area: environment variables C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
None yet
Development

No branches or pull requests

3 participants