C++: move -DFMT_UNICODE into a module patch

This commit is contained in:
Paolo Tranquilli
2025-11-20 10:47:54 +01:00
parent 83b3711973
commit b54abc7a6d
9 changed files with 139 additions and 9 deletions

View File

@@ -10,6 +10,3 @@ common --registry=https://bcr.bazel.build
common --@rules_dotnet//dotnet/settings:strict_deps=false
build --@rules_python//python/config_settings:python_version=3.12
# required to compile fmt on windows
build --copt=-DFMT_UNICODE=0 --host_copt=-DFMT_UNICODE=0

View File

@@ -23,7 +23,7 @@ bazel_dep(name = "rules_shell", version = "0.5.0")
bazel_dep(name = "bazel_skylib", version = "1.8.1")
bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "absl")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
bazel_dep(name = "fmt", version = "12.1.0")
bazel_dep(name = "fmt", version = "12.1.0-codeql.1")
bazel_dep(name = "rules_kotlin", version = "2.1.3-codeql.1")
bazel_dep(name = "gazelle", version = "0.40.0")
bazel_dep(name = "rules_dotnet", version = "0.19.2-codeql.1")

View File

@@ -35,6 +35,9 @@ def patch_json(file, **kwargs):
def update(data):
data = json.loads(data) if data else {}
data.update(kwargs)
for k, v in kwargs.items():
if v is None:
data.pop(k)
return json.dumps(data, indent=4) + "\n"
patch_file(file, update)
@@ -48,8 +51,21 @@ for entry in this_dir.joinpath("modules").iterdir():
patch_json(entry / "metadata.json", versions=[v.name for v in versions])
for version in versions:
patch_json(version / "source.json", patches={
p.name: sha256(p) for p in version.joinpath("patches").iterdir()
})
patch_file(version / "MODULE.bazel",
lambda s: re.sub(r'''version\s*=\s*['"].*['"]''', f'version = "{version.name}"', s, 1))
patches = version.joinpath("patches")
overlay = version.joinpath("overlay")
modules = [version / "MODULE.bazel", overlay / "MODULE.bazel"]
for module in modules:
if module.is_file():
patch_file(
module,
lambda s: re.sub(r'''version\s*=\s*['"].*['"]''', f'version = "{version.name}"', s, 1))
patch_json(
version / "source.json",
patches={
p.name: sha256(p) for p in patches.iterdir()
} if patches.is_dir() else None,
patch_strip=1 if patches.is_dir() else None,
overlay={
o.name: sha256(o) for o in overlay.iterdir()
} if overlay.is_dir() else None,
)

View File

@@ -0,0 +1,9 @@
module(
name = "fmt",
version = "12.1.0-codeql.1",
bazel_compatibility = [">=7.2.1"],
compatibility_level = 10,
)
bazel_dep(name = "rules_cc", version = "0.2.13")
bazel_dep(name = "rules_license", version = "1.0.0")

View File

@@ -0,0 +1,40 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_license//rules:license.bzl", "license")
package(
default_applicable_licenses = [":license"],
)
exports_files([
"LICENSE",
])
license(
name = "license",
license_kinds = ["@rules_license//licenses/spdx:MIT"],
license_text = "LICENSE",
)
cc_library(
name = "fmt",
srcs = [
#"src/fmt.cc", # No C++ module support, yet in Bazel (https://github.com/bazelbuild/bazel/pull/19940)
"src/format.cc",
"src/os.cc",
],
hdrs = glob([
"include/fmt/*.h",
]),
# codeql change: disable UTF8 support, it's causing issues on Windows
# copts = select({
# "@rules_cc//cc/compiler:msvc-cl": ["/utf-8"],
# "//conditions:default": [],
# }),
defines = select({
"@rules_cc//cc/compiler:msvc-cl": ["FMT_UNICODE=0"],
"//conditions:default": [],
}),
includes = ["include"],
strip_include_prefix = "include", # workaround: only needed on some macOS systems (see https://github.com/bazelbuild/bazel-central-registry/issues/1537)
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,9 @@
module(
name = "fmt",
version = "12.1.0-codeql.1",
bazel_compatibility = [">=7.2.1"],
compatibility_level = 10,
)
bazel_dep(name = "rules_cc", version = "0.2.13")
bazel_dep(name = "rules_license", version = "1.0.0")

View File

@@ -0,0 +1,28 @@
matrix:
unix_platform:
- debian10
- debian11
- macos
- macos_arm64
- ubuntu2004
- ubuntu2004_arm64
- ubuntu2204
- ubuntu2404
windows_test:
- windows
bazel: [7.x, 8.x, rolling]
tasks:
unix_test:
name: Verify build targets
platform: ${{ unix_platform }}
bazel: ${{ bazel }}
build_targets:
- '@fmt//:fmt'
windows_test:
name: Verify build targets
platform: ${{ windows_test }}
bazel: ${{ bazel }}
build_flags:
- --cxxopt=/utf-8
build_targets:
- '@fmt//:fmt'

View File

@@ -0,0 +1,9 @@
{
"url": "https://github.com/fmtlib/fmt/releases/download/12.1.0/fmt-12.1.0.zip",
"integrity": "sha256-aV/Rl/pa/4/Ge18rvBEEkKh1zfekFoashRL7SA+orac=",
"strip_prefix": "fmt-12.1.0",
"overlay": {
"BUILD.bazel": "sha256-T6CBBdPY92Iloq9NrMjm9kQeQA3nTZJeym6xG5cclOQ=",
"MODULE.bazel": "sha256-Dgke/2OMsffv9jPSDxIwIgJIb4L77VW6lR8TsNHsekg="
}
}

View File

@@ -0,0 +1,22 @@
{
"homepage": "https://github.com/fmtlib/fmt",
"maintainers": [
{
"email": "julian.amann@tum.de",
"github": "Vertexwahn",
"github_user_id": 3775001,
"name": "Julian Amann"
},
{
"github": "mering",
"github_user_id": 133344217
}
],
"repository": [
"github:fmtlib/fmt"
],
"versions": [
"12.1.0-codeql.1"
],
"yanked_versions": {}
}