-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Integration of code generators #204
Comments
@Be-ing I opened a new issue to discuss your request. As far as I can see you wish for the following:
I think in general, this is not only interesting for your specific project, but also for e.g. a potential However, I think providing support for 2. is not so easy, because:
|
If you don't want to unconditionally add the include paths, an option could be added to corrosion_import_crates(MANIFEST_PATH rust/src/Cargo.toml CRATES rust-crate-that-uses-cxx CXX) In case someone wants to import multiple crates, some of which use the code generator and some do not, they could make multiple calls to I don't think this is feasible in a general case; how to do this depends on the implementation details of the specific code generator. I am hoping we can reach a consensus how to handle this for cxx in dtolnay/cxx#462. If that is not accepted, Corrosion could still add a |
To clarify, for cxx and cxx-qt, I am only concerned with adding include paths for the generated headers. The code generator that runs in crates' build.rs not only generates C++, it also compiles it with the cc crate. This is important because otherwise the code generation would have to run at CMake configure time if CMake was building the generated C++ code. |
I still believe this is hard to do without the user specifying which targets should get the additional include paths.
At work we also have a custom code generator, which is run at build time. Is there something special about your project that requires running it at configure time? Have you looked at
Cmake >= 3.18 supports indirect function calls, so I think we may be able to provide some interface where downstream can customize the generator behavior via their own function. I have not thought this through at all, but maybe corrosion could provide something along the lines of:
|
I don't understand what the issue is with the user specifying which targets use the code generator. |
I think that would be overcomplicated. Users may as well add |
cxx-qt-build outputs multiple C++ files and their names are dependent on the contents of the Rust modules they are generated from, so CMake can't know at configure time what source files to add to the target without running the code generator. But that problem is already solved by compiling the generated C++ with the cc crate in build.rs. |
Ah, then this was a misunderstanding on my side. I was under the impression that you didn't want the user to have to specify which targets get the additional include paths. So then for your use-case it would be sufficient to set an environment variable pointing to a location where the code-generator should generate the code to? |
My goal is for Corrosion to handle both setting the environment variable and adding the include path so the user doesn't even need to know about these. Adding a |
Yes, if we could get cxx and cbindgen upstreams to agree to using the same environment variable, Corrosion would only need one option to handle them all. |
Sorry, but I still don't see a good way for corrosion to correctly add include paths without the user providing additional information.
To clarify, the include directories should be set via I'm open to proving an environment variable which could specify a directory such as |
I never proposed using
I don't understand how cxx or cbindgen could know where to put their output without being aware of this environment variable. |
Then I just really don't understand how you expect corrosion to know which C/C++ CMake targets should get the additional include directories. Could you give an example of how the syntax of corrosion_import_crate would look like in your vision, and how corrosion would then know which C/C++ targets need the additional include directories?
Presumably the code generator would anyway need to be called by the user, because options need to be specified. E.g. |
could set the environment variable and the include path for the
The code generators are Rust libraries called by build.rs, not CLI tools. I tried the CLI tool approach, it was not a good solution. |
Ah thanks, I think I understand a bit better now what you want. Basically you want to set
That shouldn't really matter though. From your linked issue, I it seems your problem is mainly that cxx-bridge does not support specifying the output location. Currently I'm still not convinced that this is something that needs to be done on the corrosion side. Couldn't you just add a cxx-qt wrapper aroud
|
Yes.
Strictly speaking for cxx-qt's purposes, it doesn't need to because cxx-qt-build does not use cxx-build. However, it would simplify the implementation and usage of Corrosion if cxx, cxx-qt, and hopefully cbindgen as well converged on using the same environment variable to specify the directory to output generated headers.
That is possible. cxx-qt used to have its own CMake module before using Corrosion (this was required before cxx-qt-build compiled the C++ code it generated). The problem is that requires distributing a CMake module for cxx-qt, which makes it more complicated for downstream users. It would be simpler for users of cxx-qt to only need Corrosion and have the rest handled by Cargo. |
#244 will be a first step for cxx integration. |
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
I had a discussion about this at Cargo office hours a few weeks ago. The conclusion we came to was this could be incorporated into the upcoming binary dependency feature of Cargo, where crates can specify bin crates as dependencies. If Cargo exposed a command line interface for running those binary dependencies, for example something like |
That does sound useful, but it seems there are still a number of issues remaining before |
Originally posted by @Be-ing in #150 (comment)
The text was updated successfully, but these errors were encountered: