-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[question] Toolchain as a package that injects compiler args #17825
Comments
Hi @rohel01 Thanks for your question. The When talking about toolchains and compilers, this is rarely the case, and there is no such a thing as So the idea is that toolchain tool-requires configuration flags should also go via def package_info(self):
self.conf_info.append("tools.build:cxxflags", ["-I my/include/path", ...] Please let me know if this helps. |
Thanks for your quick answer @memsharded ! Yes, this helps. I think what tripped me is that binary dirs are configured via self.cpp_info.bindirs.append(os.path.join(self.package_folder, toolchain, "bin")) I guess it is because binaries are discoverable by the build system as you mentionned, but it would be more consistent from a UX point of view to configure them via One more question, if you do not mind. When using the meson toolchain, I found some compiler executables are not picked up. In my recipe: def package_info(self):
toolchain = self.conan_data["toolchain"]
# Skipped code
# Configure compiler binaries for the build system
self.conf_info.define("tools.build:compiler_executables", {
"c": f"{toolchain}-gcc",
"cpp": f"{toolchain}-g++",
"ar": f"{toolchain}-ar",
"strip": f"{toolchain}-strip"
}) In the generated [binaries]
c = 'riscv-rtems6-gcc'
cpp = 'riscv-rtems6-g++'
[built-in options]
# ... I found out about it because of the following meson warning during install
It should work, right? |
Looking at the meson toolchain code, this behavior seems intentional. In tools/meson/toolchain.py, only the c and cpp binaries are computed from "tools.build:compiler_executables" |
Yes, the thing is that But toolchains are a bit different, as they are not a regular dependency.
In other words, if the toolchain was not inside a Conan package, it would still be possible to define the The relevant code for the compilers in Meson is: compilers_by_conf = self._conanfile_conf.get("tools.build:compiler_executables", default={},
check_type=dict)
# Read the VirtualBuildEnv to update the variables
build_env = self._conanfile.buildenv_build.vars(self._conanfile) if native else (
VirtualBuildEnv(self._conanfile, auto_generate=True).vars())
#: Sets the Meson ``c`` variable, defaulting to the ``CC`` build environment value.
#: If provided as a blank-separated string, it will be transformed into a list.
#: Otherwise, it remains a single string.
self.c = compilers_by_conf.get("c") or self._sanitize_env_format(build_env.get("CC")) or default_comp So this should work, unless you defined that conf also in your profile, where does the |
There are two separate albeit related issues. I opened this ticket because I first failed to forward compilation and link flags from a toolchain package to consuming package via [tool_requires]. Your proposal to use Now that this is solved, I noticed an other issue. At the end of the package_info method of the toolchain package, I override some compilation executables, as demonstrated by the ARM toolchain tutorial. self.conf_info.define("tools.build:compiler_executables", {
"c": f"{toolchain}-gcc",
"cpp": f"{toolchain}-g++",
"ar": f"{toolchain}-ar",
"strip": f"{toolchain}-strip"
}) (Note: After #: Defines the Meson ``strip`` variable. Defaulted to ``STRIP`` build environment value
self.strip = build_env.get("STRIP") Is it intentional? Usually, toolchains need to override a lot more than the c and cpp compilers. |
That is correct, the #: Defines the Meson ``ar`` variable. Defaulted to ``AR`` build environment value
self.ar = build_env.get("AR")
#: Defines the Meson ``strip`` variable. Defaulted to ``STRIP`` build environment value
self.strip = build_env.get("STRIP")
#: Defines the Meson ``as`` variable. Defaulted to ``AS`` build environment value So it is not picking it up from |
For reference, the following pr and issues mention modifications to
|
We have been reviewing this.
Actually not quite! What we have found in "most cases" is the opposite - that most build systems are able to derive the name of the tools directly from the compiler and/or the target platform. For instance, for a gcc compiler toolchain, if I set the compiler to Some other tools like assembler and linker tend to be invoked via the compiler - so defining them doesn't make sense for most users and is more likely to cause issues e.g.:
It may be that:
For your case, where I can see
I suspect that defining only gcc and g++ would work for the vast majority of "compliant" build systems and scripts (CMake, autootols), with the build systems correctly deriving the tooling without having to specify them. I have a feeling that the only reason
Possibly the implementation in As it stands right now, we don't have this for
|
The current toolchains we are using for a RISCV SoC overrides gcc, g++, addr2line, ar, gcov, gprof, ranlib, objcopy, size, strings and strip. I mean override in the sense the toolchain provides specific (prefixed) versions of these executables. I agree users should provide minimal information so to prevent inconsistencies between tools involved in the same workflow.
ar is overriden in the Conan ARM toolchain tutorial :) I like that, by default, we can rely on some compiler driver heuristic to select consistent tools to be involved in the build. My surprise here is that there is a documented way to be explicit, but then my request is ignored. The ability to selectively override tools is useful there because
If I cannot override and the tool is guessing wrong, then I start fighting the very tools I wanted to rely on. There are concrete examples where overriding is or would have been useful
What is a "compliant" build system? One of the key reasons I want to deploy Conan in my company is I can use profiles to enforce consistent build constraints (flags, toolchain depencenies) in a build system independent way: I do not need to duplicate profile specifications across each (internal or external) team build system and yet, each of those team can pick the build system of their choice (as long as it is supported by Conan) and still use the company's profiles. Conan acting as a consistency layer between non cooperating stakeholders and technologies is a huge benefit for me. Here, we have a concrete case were the behavior depends on the actual build backend. I do not think this is something we want. Maybe
Yes, I will test that tomorrow. I expect this workaround will work. Thanks you for suggesting it. |
In our experience, most build systems know the gcc prefixing conventions and are able to derive all those tools with little information (either the compiler alone, the The problem that we are seeing, is that when users are "too" specific - they tend to pick the wrong executables, or not in the right way, which causes issues. So on the one hand, yes - being explicit could be beneficial, but on the other hand, it's causing users to shoot themselves in the foot more often than not.
I think there's some confusion here.
I think more spefically, it doesn't handle finding However, this can be solved by following a variation of What seems to be missing for most users is that
Happy to hear this!
We have a behaviour that is just not implemented I think more specifically, as a summary:
|
What is your question?
Hello,
I am using Conan 2.12.2.
I have a similar use case than the one explained in the tutorial "Creating a Conan package for a toolchain". In my case though, the toolchain must also inject specific argument on the compiler command lines: specific includes, link libraries and scripts for example.
So, I modified the
package_info
method from the example as follows:However, these compiler flags do not end up being used in consuming packages. Furthermore, I cannot just put them in a profile, since they use the path of the toolchain package.
Any ideas?
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: