This is an archive of the discontinued LLVM Phabricator instance.

[Bazel] Use `LLVM_VERSION` from `llvm/CMakeLists.txt`
ClosedPublic

Authored by chapuni on Oct 20 2022, 4:27 PM.

Details

Summary
  • Generate //:vars.bzl from llvm/CMakeLists.txt

_extract_cmake_settings() generates //:vars.bzl in llvm_configure().
It would be easier to use external commands like sed(1) and python.
For portability, I think the parser should run on Starlark.

@llvm-project//:vars.bzl may be loaded from both WORKSPACE and BUILD.
At the moment, vars.bzl provides some values as string.

  • CMAKE_CXX_STANDARD = "17"
  • LLVM_VERSION_MAJOR = "16"
  • LLVM_VERSION_MINOR = "0"
  • LLVM_VERSION_PATCH = "0"
  • LLVM_VERSION = "16.0.0"
  • llvm_vars = (dict of these values)

CMAKE_CXX_STANDARD may be used to configure toolchain.

  • Use //vars.bzl for each BUILD files

It would be smarter if the BUILD phase could generate llvm-config.h.
Since I am afraid of the discussion in D126581, I just remove
LLVM_VERSION stuff out of the static llvm-config.h.

  • Eliminate Bazel stuff in 'bump-version.py'

Current version of bump-version.py tries to substitute CLANG_VERSION.
It is the reason why I modify bump-version in this change rather than
upcoming patches.

Diff Detail

Event Timeline

chapuni created this revision.Oct 20 2022, 4:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2022, 4:27 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
chapuni requested review of this revision.Oct 20 2022, 4:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2022, 4:27 PM

Thanks for improving the Bazel build. I unfortunately don't know enough about Bazel... but I can try finding some folks who can help.

For one thing, there are some style issues, especially whether an operator has adjacent space like if setfoo[1]!="(": => if setfoo[1] != "(":

MaskRay added inline comments.Oct 24 2022, 9:08 PM
utils/bazel/llvm-project-overlay/clang/BUILD.bazel
392

Let me try removing this cmake variable in D136660

thakis resigned from this revision.Oct 25 2022, 5:49 AM

Are there practical portability concerns about doing this in Python? I'm not aware of a platform where Bazel runs that Python doesn't. I do like pulling this directly from the CMake in the cases where the values are set there. I think there was discussion at some point of whether it would be easier if these values were encoded somewhere in a simple text file. Here we go: https://discourse.llvm.org/t/rfc-centralized-location-for-version-information/65295. Might be good to follow-up on where that went

chapuni updated this revision to Diff 487160.Jan 8 2023, 4:22 AM
chapuni retitled this revision from [bazel] Generate `//:vars.bzl` from `llvm/CMakeLists.txt` to [Bazel] Use `LLVM_VERSION` from `llvm/CMakeLists.txt`.
chapuni edited the summary of this revision. (Show Details)
  • Caught up recent changes
  • Reformat
  • Use string.format() if possible
  • Eliminate Bazel stuff in 'bump-version.py'
chapuni marked an inline comment as done.Jan 8 2023, 4:43 AM

Thank you @GMNGeoffrey for the comment and I am sorry for the delay.

Are there practical portability concerns about doing this in Python? I'm not aware of a platform where Bazel runs that Python doesn't.

It is my preference. Still I think that external tools may be avoided as possible in repository rules.
At the moment I don't use other platforms like Windows. I haven't met any portability issues but I would like to prevent them.
In my experiences, Python has not been easy for portability, configurability, version and platforms.

(I could use platform-specific tools to implement platform-specific functionality. For example, to import repositories from *.deb or installed deb packages)

FYI, the prototype was using sed(1). It was simpler but I gave it up due to portability concern.

I know my implementation by Starlark is not smart but I expect it may be removed in the near future when we could introduce the centralized version database file.

chapuni added a subscriber: thieta.

@thieta Could you confirm my changes in bump-version.py?

thieta accepted this revision.Jan 8 2023, 4:48 AM

Thanks for making this change. I think the changes to the bump script looks fine if no processing is needed in the future.

This revision is now accepted and ready to land.Jan 8 2023, 4:48 AM

This looks like a nice improvement! Just one thing I noticed.

utils/bazel/configure.bzl
144

I see a warning that vars is unused here and should be removed. Did you mean to have _extract_cmake_settings() only parse the information, and have a separate helper method that actually writes out the file, i.e. split the previous method at # Write out individual vars?

chapuni updated this revision to Diff 488637.Jan 12 2023, 6:38 AM
  • [Bazel] Split out _write_dict_to_file
chapuni added inline comments.Jan 12 2023, 6:47 AM
utils/bazel/configure.bzl
144

I just thought vars might be used later after _extract_cmake_settings in _llvm_configure_impl.

Did you mean to have _extract_cmake_settings() only parse the information, and have a separate helper method that actually writes out the file, i.e. split the previous method at # Write out individual vars?

I could just remove an assignment but it really makes sense.
I have introduced _write_dict_to_file.

MaskRay accepted this revision.Jan 13 2023, 11:13 AM
MaskRay added inline comments.
utils/bazel/configure.bzl
75

Nit: We don't add a blank line after def:

131

Nit: We don't add a blank line after def:

This revision was landed with ongoing or failed builds.Jan 13 2023, 5:26 PM
This revision was automatically updated to reflect the committed changes.
chapuni marked 2 inline comments as done.