Comments (13)
Hi @JonathanDCohen, you can pass CMake's CFLAGS or CXXFLAGS with env_vars attribute of cmake_external rule.
Please note that we also take all the flags from Bazel's cc_toolchain and convert them to corresponding CMake environment variables or cache initializers, so you may already be fine with most flags.
cmake_external was designed to be similar to cc_library by the set of attributes and outputs. For instance, you can pass cc_library targets as dependencies and pass cmake_external as dependencies into other cc_libraries.
from rules_foreign_cc.
Do we want to clobber CXXFLAGS?
For more context, Abseil has a bunch of standard copts we put on every target (https://github.com/abseil/abseil-cpp/blob/master/absl/copts.bzl) so I'd need some way to specify those flags in addition to whatever bazel or cmake would normally put there
from rules_foreign_cc.
It is possible to convert these flags into a space-separated string in a BUILD file and pass the result with env_vars (example of this option usage (though referring to locally installed python, which is not correct)).
The values that are passed from Bazel's cc_toolchain into CXXFLAGS will be merged with the passed flags.
The passed values for CXXFLAGS will not be propagated to the dependants of that cmake_external target.
from rules_foreign_cc.
@irengrig does this also cover --cxxopt
as specified on Bazel CLI?
from rules_foreign_cc.
@irengrig following your offline suggestion, I instrumented get_flags_info()
. I set some coverage related flag, call it -fblah
, in --cxxopt
, --conlyopt
, --linkeropt
and --host_linkeropt
on Bazel CLI.
The only place -fblah
appears is in cxx_linker_executable
and cxx_linker_shared
, it doesn't show up in cc
or cxx
in flags info.
It seems this is a bug or missing feature, we should be able to propagate the compiler options from Bazel CLI down to the cmake
target. Would be awesome to have this supported.
from rules_foreign_cc.
@irengrig I also think this affects configure_make
, which is how we setup two of our external deps (gperftools, LuaJIT). Specifically, we're not seeing these copt
flags in the configure
phase.
from rules_foreign_cc.
Please verify the fix #235, the --copt etc. options should be read by rules_foreign_cc now.
from rules_foreign_cc.
Lookin gback at this, I think rules_foreign_cc isn't what I Was looking for anyways. This builds a CMake lib using Bazel -- I want to generate a CMake buildsystem from a Bazel buildsystem. It seems like other people are working on this though so I won't close
from rules_foreign_cc.
Er, just curious: When you say "generate a CMake buildsystem", do you mean emitting the relevant config files to then be consumed by a downstream CMake project?
from rules_foreign_cc.
from rules_foreign_cc.
Gotcha, thanks for the explanation!
If it's useful to you, we also ran into this for drake, and made a solution for generating CMake artifacts for consumption via downstream CMake projects (at a loss of target granularity and only for shared libs for now):
https://github.com/RobotLocomotion/drake/blob/015998c4f/CMakeLists.txt#L426
https://github.com/RobotLocomotion/drake/blob/015998c4f/BUILD.bazel#L53
https://github.com/RobotLocomotion/drake/blob/015998c4f/tools/install/libdrake/BUILD.bazel#L75
Example usage:
https://github.com/RobotLocomotion/drake-external-examples/tree/43ff258/drake_cmake_installed#instructions
This is not a perfect solution by any means, but has been working for us thus far.
Definitely looking forward to seeing what solution y'all converge on!
from rules_foreign_cc.
I can confirm that #235 fixes the issues we were observing in Envoy.
from rules_foreign_cc.
Closing as the issue with passing flags transitively was solved by #235 .
Tests are here: https://github.com/bazelbuild/rules_foreign_cc/tree/master/test/standard_cxx_flags_test
from rules_foreign_cc.
Related Issues (20)
- Consider adding `toolchains` parameter to `configure_make_variant`
- Absolute paths in native_tool_toolchain result in "Can not copy" error
- Issue enabling `layering_check` HOT 2
- Meson lacks support for cross compilation HOT 4
- Enable changing cmake versions with bzlmod HOT 1
- Call to build toolchains (rules_foreign_cc_dependencies()) is not working
- Put toolchain default library flags in LDFLAGS broke many projects on Darwin
- using cmake to build abseil failed HOT 2
- RFC: Add support for `CPPFLAGS` and clean up `CxxFlagsInfo`
- Default rules_foreign_cc_dependencies call fails - `no such package '@@rules_foreign_cc//toolchains'` HOT 4
- meson_with_requirements causes build configuration explode
- Help with Openssl for Bazel HOT 1
- invalid registered toolchain '@rules_foreign_cc//toolchains:preinstalled_nmake_toolchain': No repository visible as '@rules_foreign_cc' from main repository HOT 9
- cc_shared_library targets cannot be used as deps
- [Bazel CI] CcMesonMakeRule Fails with Linker Error, Build Fails HOT 3
- configure_make set linkopts with "$$EXT_BUILD_DEPS$$"" will let linker cannot find coresponding directory
- configure stage inconsistent with compiling stage when specify --sysroot for building BootstrapGNUMake HOT 1
- runnable_binary generated a zero-length wrapper, but succeeded
- invoke wrong make name when cross compiling for windows HOT 2
- Sandbox makes build non-deterministic when building with debug symbols HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rules_foreign_cc.