[SERVER-81425] Automatically detect C files in bazel toolchain Created: 25/Sep/23  Updated: 18/Dec/23  Resolved: 08/Nov/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.3.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Zack Winter Assignee: Zack Winter
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-80603 Support --use-libunwind=[on|off|auto]... Closed
is depended on by SERVER-82620 libunwind broken in bazel build Closed
Assigned Teams:
Build
Backwards Compatibility: Fully Compatible
Participants:

 Description   

With the current toolchain *.c files are being compiled with g+/clang+ which define the macro `__cplusplus`. This is incorrect and breaks the ability to properly compile a large number of C targets.

Modify the toolchain to detect .c files and instead compile them with gcc/clang.



 Comments   
Comment by Githook User [ 08/Nov/23 ]

Author:

{'name': 'Zack Winter', 'email': 'zack.winter@mongodb.com', 'username': 'zackwintermdb'}

Message: SERVER-81425 remove separate target for tcmalloc c targets
Branch: master
https://github.com/mongodb/mongo/commit/9b1e87713ccb72ac49b351f75a6e5f190dfafbf7

Comment by Githook User [ 06/Nov/23 ]

Author:

{'name': 'Zack Winter', 'email': 'zack.winter@mongodb.com', 'username': 'zackwintermdb'}

Message: SERVER-81425 Automatically detect C files in bazel toolchain
Branch: master
https://github.com/mongodb/mongo/commit/b75a05bcd7db73d50df4552582a06e9548537385

Comment by Zack Winter [ 19/Oct/23 ]

In master we're relying on a macro around the native `cc_library` right now so I don't think there's a way to select a toolchain based on the extension of each source code as-is: https://github.com/mongodb/mongo/blob/master/bazel/mongo_src_rules.bzl#L5

If we switch to implementing our own version of `cc_library/program/etc` like in the POC we can select the toolchain based off of the extension.

Do you think we won't be able to rely on the native versions of these to support all of the features we need? It would be great if we could rely on the built in bazel cc rules to do a lot of the manual work, but I'm not sure how far defining our own toolchain config will get us.

Comment by Zack Winter [ 19/Oct/23 ]

Notes from meeting with daniel.moody@mongodb.com - we will want to require this before flipping the switch on requiring bazel since there are subtle differences between gcc/clang & g+/clang+

We can do this either by:

  1. Defining our own toolchain config implementation and switching between compiler depending on the bazel action (see https://github.com/carbon-language/carbon-lang/blob/trunk/bazel/cc_toolchains/clang_cc_toolchain_config.bzl#L85 for example) This would allow interleaving C & C++ source in a single target
  2. Creating a new set of toolchain configs for C & creating a set of C build macros that use those (ex. a "mongo_c_library" version of https://github.com/mongodb/mongo/blob/master/bazel/mongo_src_rules.bzl#L5

The second is a bit messy since it's yet another dimension of toolchain configs, which is already pretty huge (arch, OS, compiler), but it's a much simpler implementation.

Generated at Thu Feb 08 06:46:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.