Skip to content

[feature request] Allow users to add extra extension names for C/C++ toolchains. #2298

Closed as not planned

Description

@ahyangyi

Hi,

One of the reasons that I am still using an internal fork of Bazel is that we need to support CUDA programs with their .cu extensions. As CUDA is deeply integrated with C/C++ toolchains, and is usually supposed to be linked together with C/C++ object files with shared headers, it does not really make sense to treat it as a separate language.

My current solution to support CUDA is that I modified Bazel to include ".cu" as another file extension to indicate a C++ source file. Then I grabbed a wrapper from Tensorflow and slightly modified it so it would call nvcc when a .cu file is given and call gcc otherwise.

This works nicely. However, I believe there's some insight in this home-baked solution: a simple feature that allows us to instruct Bazel to treat some file extensions in the same way as some existing extensions, would enable users to support the many existing C/C++ compatible languages without reinventing the wheel that is C/C++ toolchain support.

Thanks.

Activity

  1. added
    P2
    on Dec 27, 2016
  2. hlopko commented on Jan 2, 2017

    @hlopko
    Member

    @lberki Wdyt?

  3. lberki commented on Jan 2, 2017

    @lberki
    Contributor

    We'll eventually need to do this. The original motivation is not source files, but that output files (object files, libraries, executables and such) have different extensions in different operating systems. And once we have that, it's not a big stretch to extend the same thing to source files, too.

  4. self-assigned this
    on Sep 22, 2017
  5. added
    team-Rules-CPP
    and removed on Oct 11, 2018
  6. hlopko commented on Jan 10, 2019

    @hlopko
    Member

    This has been already done (we still require the extension to be from a limited set). I see artifact_name_pattern is not documented on https://docs.bazel.build/versions/master/crosstool-reference.html so I'll leave this issue open to improve the docs.

  7. Riatre commented on Feb 11, 2019

    @Riatre

    IIUC artifact_name_pattern controls what @lberki mentioned above, but the original feature request is slightly different, it asks for adding extra extensions for input source files instead of artifacts, so I don't think this has been already done and is a documentation-only issue.

    To be more precise, what is requested here is to allow modifying com.google.devtools.build.lib.rules.cpp.CppFileTypes.CPP_SOURCE and CPP_HEADER (adding .cu and .cuh correspondingly) without patching Bazel itself.

    This may become irrelevant if the C++ sandwich eventually leads to a proper cuda_library implementation though.

  8. self-assigned this
    on Mar 6, 2019
  9. removed their assignment
    on Dec 6, 2019
  10. celentes commented on Mar 13, 2021

    @celentes

    Friendly ping. What is the status on this?

    Various compilers introduce different extension names for different kind of inputs/outputs, e.g. emscripten can compile libraries into .bc files and executable output is going to be several files of .js, .wasm and some optional extras, which currently need to be resorted to workarounds when working with bazel.
    I feel like all of that configuration should be specified in the toolchain providers rather than hardcoded in bazel internals for each different os/arch/compiler combination.

    What is the motivation behind restricting these?

  11. oquenchil commented on Mar 16, 2021

    @oquenchil
    Contributor

    I think different actions are triggered depending on the extension. Last time someone sent a PR to remove all checks, we got tests failing internally in our mono-repo because of the way a file with an assembly extension was being handled. We won't spend time on this for now but you are welcome to investigate a refactoring that would remove the restriction while keeping current behavior, i.e.: which actions are triggered by which files stays the same.

  12. github-actions commented on May 1, 2023

    @github-actions

    Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 2+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

  13. added
    stale
    on May 1, 2023
  14. github-actions commented on May 15, 2023

    @github-actions

    This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2staleteam-Rules-CPPtype: feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions