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

Add feature cxxbridge to allow user manually compile it #1243

Closed
wants to merge 1 commit into from

Conversation

yujincheng08
Copy link
Contributor

@yujincheng08 yujincheng08 commented Jul 7, 2023

Sometimes we want to manually compile the cxxbridge (e.g., we use our own toolchain for embedded devices). Thus we introduce a cxxbridge which is enabled by default and users can disable it and generate and compile their own bridges using customized toolchains.

I saw #1196 (review) but I still think this feature is necessary. For example, if I have multiple static libraries and need to integrate some Rust codes into them. If I am not able to disable compelling cxxbridge, I will have multiple cxxbridge on different static libraries. And linking will fail with duplicate symbols. If I could disable cxxbridge, I can only compile it on a commonly linked library.

In this patch, I also export two functions (i.e., export_cxx_bridge and generate_header_and_cc_with_path) for c build systems (like cmake or gnumake). There are many reasons that we still need a c build system (e.g., cargo does not support post-build scripts). With the two newly exported functions, we can integrate rust codes into c build systems.

Sometimes we want to manually compile the `cxxbridge` (e.g., we
use our own toolchain for embedded devices). Thus we introduce a
`cxxbridge` which is enabled by default and user can disable it and
generate and compile their own bridges using customized toolchains.
@yujincheng08
Copy link
Contributor Author

@dtolnay sorry for pinging. any comment?

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

I am skeptical about this PR because I have not seen any other library that compiles native code in its build script need to do this.

The use case you described is multiple static libraries which each include the cxx crate. I am not clear on how eliding the C half of the cxx crate from those static libraries addresses the use case. All the static libraries would still include the Rust half of the cxx crate and those would be duplicate symbols.

@yujincheng08
Copy link
Contributor Author

Here you are a project (I am one of its maintainers):

https://github.com/topjohnwu/Magisk/tree/master/native/src

It now needs to use a modified version of cxx to avoid building cxxbridge.

All the static libraries would still include the Rust half of the cxx crate and those would be duplicate symbols.

I think it won't include duplicate symbols. The rust part (and all deps) wont be included in the output static libraries. They are stored in separate libraries which will link only into the final elf. However, cxxbridge will include in our own static libraries and thus cause duplicate symbol errors.

@yujincheng08 yujincheng08 deleted the cxxbridge branch February 20, 2024 14:48
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.

2 participants