Code Monkey home page Code Monkey logo

Comments (13)

irengrig avatar irengrig commented on August 30, 2024

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.

JonathanDCohen avatar JonathanDCohen commented on August 30, 2024

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.

irengrig avatar irengrig commented on August 30, 2024

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.

htuch avatar htuch commented on August 30, 2024

@irengrig does this also cover --cxxopt as specified on Bazel CLI?

from rules_foreign_cc.

htuch avatar htuch commented on August 30, 2024

@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.

htuch avatar htuch commented on August 30, 2024

@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.

irengrig avatar irengrig commented on August 30, 2024

Please verify the fix #235, the --copt etc. options should be read by rules_foreign_cc now.

from rules_foreign_cc.

JonathanDCohen avatar JonathanDCohen commented on August 30, 2024

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.

EricCousineau-TRI avatar EricCousineau-TRI commented on August 30, 2024

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.

JonathanDCohen avatar JonathanDCohen commented on August 30, 2024

from rules_foreign_cc.

EricCousineau-TRI avatar EricCousineau-TRI commented on August 30, 2024

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.

htuch avatar htuch commented on August 30, 2024

I can confirm that #235 fixes the issues we were observing in Envoy.

from rules_foreign_cc.

irengrig avatar irengrig commented on August 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.