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

Support for sharedlinkflags and exelinkflags #13

Open
allenli873 opened this issue Nov 27, 2024 · 7 comments
Open

Support for sharedlinkflags and exelinkflags #13

allenli873 opened this issue Nov 27, 2024 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@allenli873
Copy link
Contributor

I noticed that visit_cpp_component doesn't expose the Conan settings sharedlinkflags and exelinkflags. It appears that sharedlinkflags could just map to cargo::rustc-link-arg={flags}, and exelinkflags could map to cargo::rustc-link-arg-bin=${CARGO_BIN_NAME}={flags} if the CARGO_BIN_NAME environment variable is set?

Happy to submit a PR as well if wanted.

@ravenexp ravenexp self-assigned this Nov 27, 2024
@ravenexp ravenexp added the enhancement New feature or request label Nov 27, 2024
@ravenexp
Copy link
Owner

This seems reasonable. But shouldn't sharedlinkflags only be applied for cdylib Rust crates? I'm not sure about this part. I'd happily review a PR, but I have no time to implement it myself atm.

It would be great if you could find a package that actually sets these properties on conancenter and add it to tests/conanfile.txt.

Also, some kind of a test case in integration_test.rs is much appreciated. Simply searching for cargo::rustc-link-arg=X in the emitted strings is fine.

@allenli873
Copy link
Contributor Author

I'm also not super sure about only applying to cdylib crates, and after looking around am not fully sure there's an easy way to detect this. Can you think of adverse effects of not putting this detection in?

@ravenexp
Copy link
Owner

I'm also not super sure about only applying to cdylib crates, and after looking around am not fully sure there's an easy way to detect this. Can you think of adverse effects of not putting this detection in?

I've looked at how sharedlinkflags are actually used by Conan generators, and it appears that they are only applied for shared library targets. For example in the CMake generator:

https://github.com/conan-io/conan/blob/develop2/conan/tools/cmake/toolchain/blocks.py#L738
https://github.com/conan-io/conan/blob/develop2/conan/tools/cmake/toolchain/blocks.py#L832

OTOH, GNU autotools and meson generators just lump all linkflags together:

https://github.com/conan-io/conan/blob/develop2/conan/tools/meson/toolchain.py#L429
https://github.com/conan-io/conan/blob/develop2/conan/tools/gnu/autotoolsdeps.py#L52

As for the adverse affects, I'm not sure, because the Conan package authors can put literally anything there. Some GCC linker flags are only applicable to DSO outputs and raise a link error when used with executables. I'd prefer to err on the safe side and try to do what the CMake generator currently does.

As for the automatic detection, I don't think this can be done in the build scripts. CARGO_BIN_NAME can only be seen by rustc when compiling the crate and not by the build script where conan2-rs is normally used. I think adding cargo::rustc-link-arg-bins=FLAG should be safe. Maybe we should wait until Cargo implements cargo::rustc-link-arg-cdylibs= too?

@allenli873
Copy link
Contributor Author

Makes sense to me, thanks. Putting up a PR momentarily.

@ravenexp
Copy link
Owner

I've merged the exelinkflags part, but let's keep the issue open until a suitable solution for sharedlinkflags is found.

Do you need a new tagged release with #14 ASAP or can I wait until I have time to address e.g. #9 ?

@allenli873
Copy link
Contributor Author

Thanks! I'd prefer a tagged release ASAP if it's not too much hassle for you.

@ravenexp
Copy link
Owner

Thanks! I'd prefer a tagged release ASAP if it's not too much hassle for you.

Released v0.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants