C++ / ObjC / C specific `copts`

275 views
Skip to first unread message

Jerry Marino

unread,
May 2, 2018, 4:46:29 PM5/2/18
to bazel-discuss, Rahul Malik, Michael Schneider, Adlai Holler
Hello,

I'd like the ability to set language specific copts, for C, ObjC, and C++ files in a given objc_library.

This issue is that I've got some large libraries:

objc_libary(
  name = "some",
  srcs = [ A.c, B.m, C.mm, D.cxx, ... ]
)

But some of the C++ code needs compiler options that are not compatible with ObjC.

Under Xcode, it is possible to set  CLANG_CXX_LANGUAGE_STANDARD and CLANG_CXX_LIBRARY, and OTHER_CPLUSPLUS at the library level. These flags are conditionally applied based on language / file type.

Is there a way to achieve this other than creating a library for each language?

Thanks,
Jerry

Marcel Hlopko

unread,
May 3, 2018, 1:34:15 AM5/3/18
to jerry...@pinterest.com, bazel-discuss, rma...@pinterest.com, schn...@pinterest.com, ad...@pinterest.com
Hi Jerry,
afaik this is not possible today. If there are no circular deps between objects then splitting into multiple (objc|cc)_libraries is the right solution. We are currently discussing smth related, we might write a design doc soon-ish, but it's very unlikely that we will implement it before https://github.com/bazelbuild/bazel/issues/4570 is fixed.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAGCAkix6NL%2Bj6LGo8-5axWW_w1hpEbg70fMxr14wcRaMK%2BUYSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

Jerry Marino

unread,
May 8, 2018, 9:22:45 PM5/8/18
to Marcel Hlopko, bazel-discuss, Rahul Malik, Michael Schneider, Adlai Holler
Hey Marcel,

Thanks for clarifying this, Sir!

For context, a few CocoaPods are leveraging CLANG_CXX_LANGUAGE_STANDARD and there is no telling what the user defined targets will look like in CocoaPods. Unfortunately, the CocoaPod spec relies on this behavior of Xcode in order for it to work. If we aren't transitively building / linking all of the static archives, I think splitting out the C++ files will generalize to arbitrary inputs. 

BTW, we probably need to do the same splitting logic  for swift_library so I'm not too reluctant to implement this in PodToBUILD.

Much appreciated!
Jerry






On Wed, May 2, 2018 at 10:33 PM, Marcel Hlopko <hlo...@google.com> wrote:
Hi Jerry,
afaik this is not possible today. If there are no circular deps between objects then splitting into multiple (objc|cc)_libraries is the right solution. We are currently discussing smth related, we might write a design doc soon-ish, but it's very unlikely that we will implement it before https://github.com/bazelbuild/bazel/issues/4570 is fixed.

On Wed, May 2, 2018 at 10:46 PM 'Jerry Marino' via bazel-discuss <bazel-discuss@googlegroups.com> wrote:
Hello,

I'd like the ability to set language specific copts, for C, ObjC, and C++ files in a given objc_library.

This issue is that I've got some large libraries:

objc_libary(
  name = "some",
  srcs = [ A.c, B.m, C.mm, D.cxx, ... ]
)

But some of the C++ code needs compiler options that are not compatible with ObjC.

Under Xcode, it is possible to set  CLANG_CXX_LANGUAGE_STANDARD and CLANG_CXX_LIBRARY, and OTHER_CPLUSPLUS at the library level. These flags are conditionally applied based on language / file type.

Is there a way to achieve this other than creating a library for each language?

Thanks,
Jerry

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.

Marcel Hlopko

unread,
May 11, 2018, 6:55:23 AM5/11/18
to jerry...@pinterest.com, bazel-discuss, rma...@pinterest.com, schn...@pinterest.com, ad...@pinterest.com
Thanks for the clarification. It's slightly more complicated than just setting a copt, as bazel compiles files differently when it knows it's a C++ file vs ObjC file or C file. Also (new) crosstool can differentiate between them (c-compile vs c++-compile vs objc-compile vs objc++-compile action_configs). Is it an option for you to create a custom crosstool that adds a feature that you can enable for the target, that only applies to specific filetype? In other words, can *all* C++ files in the target be compiled with the copt in question?

If you have no idea what action_config and feature in the crosstool mean, I apologize, there is exactly zero documentation about this. This will change in Q2 or early Q3.

On Wed, May 9, 2018 at 3:22 AM Jerry Marino <jerry...@pinterest.com> wrote:
Hey Marcel,

Thanks for clarifying this, Sir!

For context, a few CocoaPods are leveraging CLANG_CXX_LANGUAGE_STANDARD and there is no telling what the user defined targets will look like in CocoaPods. Unfortunately, the CocoaPod spec relies on this behavior of Xcode in order for it to work. If we aren't transitively building / linking all of the static archives, I think splitting out the C++ files will generalize to arbitrary inputs. 

BTW, we probably need to do the same splitting logic  for swift_library so I'm not too reluctant to implement this in PodToBUILD.

Much appreciated!
Jerry





On Wed, May 2, 2018 at 10:33 PM, Marcel Hlopko <hlo...@google.com> wrote:
Hi Jerry,
afaik this is not possible today. If there are no circular deps between objects then splitting into multiple (objc|cc)_libraries is the right solution. We are currently discussing smth related, we might write a design doc soon-ish, but it's very unlikely that we will implement it before https://github.com/bazelbuild/bazel/issues/4570 is fixed.

On Wed, May 2, 2018 at 10:46 PM 'Jerry Marino' via bazel-discuss <bazel-...@googlegroups.com> wrote:
Hello,

I'd like the ability to set language specific copts, for C, ObjC, and C++ files in a given objc_library.

This issue is that I've got some large libraries:

objc_libary(
  name = "some",
  srcs = [ A.c, B.m, C.mm, D.cxx, ... ]
)

But some of the C++ code needs compiler options that are not compatible with ObjC.

Under Xcode, it is possible to set  CLANG_CXX_LANGUAGE_STANDARD and CLANG_CXX_LIBRARY, and OTHER_CPLUSPLUS at the library level. These flags are conditionally applied based on language / file type.

Is there a way to achieve this other than creating a library for each language?

Thanks,
Jerry

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

Jerry Marino

unread,
May 11, 2018, 5:21:47 PM5/11/18
to Marcel Hlopko, bazel-discuss, Rahul Malik, Michael Schneider, Adlai Holler
Hey Marcel,

Thanks for clarifying! I noticed that we can set specific lang options at the `CROSSTOOL` file level - perhaps this is the old toolchain setup.

I haven't head luck getting the new toolchain working yet.

But, if we can set C++ specific options in a toolchain that apply to all C++/ObjC++ ( but not Objc/C ) in the given objc_library then it should work. TBH I'm not too familiar with the abilities of the new toolchain feature or the implementation.

Cheers!
Jerry



On Fri, May 11, 2018 at 3:54 AM, Marcel Hlopko <hlo...@google.com> wrote:
Thanks for the clarification. It's slightly more complicated than just setting a copt, as bazel compiles files differently when it knows it's a C++ file vs ObjC file or C file. Also (new) crosstool can differentiate between them (c-compile vs c++-compile vs objc-compile vs objc++-compile action_configs). Is it an option for you to create a custom crosstool that adds a feature that you can enable for the target, that only applies to specific filetype? In other words, can *all* C++ files in the target be compiled with the copt in question?

If you have no idea what action_config and feature in the crosstool mean, I apologize, there is exactly zero documentation about this. This will change in Q2 or early Q3.
On Wed, May 9, 2018 at 3:22 AM Jerry Marino <jerry...@pinterest.com> wrote:
Hey Marcel,

Thanks for clarifying this, Sir!

For context, a few CocoaPods are leveraging CLANG_CXX_LANGUAGE_STANDARD and there is no telling what the user defined targets will look like in CocoaPods. Unfortunately, the CocoaPod spec relies on this behavior of Xcode in order for it to work. If we aren't transitively building / linking all of the static archives, I think splitting out the C++ files will generalize to arbitrary inputs. 

BTW, we probably need to do the same splitting logic  for swift_library so I'm not too reluctant to implement this in PodToBUILD.

Much appreciated!
Jerry





On Wed, May 2, 2018 at 10:33 PM, Marcel Hlopko <hlo...@google.com> wrote:
Hi Jerry,
afaik this is not possible today. If there are no circular deps between objects then splitting into multiple (objc|cc)_libraries is the right solution. We are currently discussing smth related, we might write a design doc soon-ish, but it's very unlikely that we will implement it before https://github.com/bazelbuild/bazel/issues/4570 is fixed.

On Wed, May 2, 2018 at 10:46 PM 'Jerry Marino' via bazel-discuss <bazel-discuss@googlegroups.com> wrote:
Hello,

I'd like the ability to set language specific copts, for C, ObjC, and C++ files in a given objc_library.

This issue is that I've got some large libraries:

objc_libary(
  name = "some",
  srcs = [ A.c, B.m, C.mm, D.cxx, ... ]
)

But some of the C++ code needs compiler options that are not compatible with ObjC.

Under Xcode, it is possible to set  CLANG_CXX_LANGUAGE_STANDARD and CLANG_CXX_LIBRARY, and OTHER_CPLUSPLUS at the library level. These flags are conditionally applied based on language / file type.

Is there a way to achieve this other than creating a library for each language?

Thanks,
Jerry

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | GermanyGeschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

Shimin Guo

unread,
May 11, 2018, 7:14:12 PM5/11/18
to jerry...@pinterest.com, bazel-discuss, rma...@pinterest.com, schn...@pinterest.com, ad...@pinterest.com
Do the --conlyopt, --cxxopt, --objccopt flags do what you want?

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Marcel Hlopko

unread,
May 14, 2018, 11:55:33 AM5/14/18
to shimi...@mixpanel.com, jerry...@pinterest.com, bazel-discuss, rma...@pinterest.com, schn...@pinterest.com, ad...@pinterest.com
Shimin, that's a good suggestion, although those flags cannot be set in BUILD files, and that's what I think Jerry needs.

Jerry, I believe you're using osx crosstool similar to this one:


There you can add something like this feature:

feature {
name: "foo_feature"
flag_set {
action: "c-compile"
flag_group {
flag: "-i_am_only_added_to_c_compile_actions"
}
}
flag_set {
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-header-preprocessing"
action: "c++-module-compile"
action: "c++-module-codegen"
flag_group {
flag: "-i_am_only_added_to_c++_compile_actions"
}
}
flag_set {
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "-i_am_only_added_to_objc_or_objc++_compile_actions"
}
}
}

Then in the build file:

objc_library(
name = "foo",
feature = [ "foo_feature" ].
)

This should add flags to the command line.


For more options, visit https://groups.google.com/d/optout.

Thien Pham

unread,
Aug 15, 2021, 12:32:28 AM8/15/21
to bazel-discuss
Hi All,

I got the same linker issue between Objective-C and C++. I asked question at Stack overflow: https://stackoverflow.com/questions/68782350/build-bazel-with-opencv-error-undefined-symbols-for-architecture-x86-64
Can anyone help me ?

Reply all
Reply to author
Forward
0 new messages