Skip to content

Commit e604d82

Browse files
Merge pull request #834 from jchadwick-buf/fix-antlr4-windows
Fix antlr4 parser generation on Windows
2 parents 9a8b79d + 7566cb9 commit e604d82

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

bazel/antlr.bzl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ def antlr_cc_library(name, src, package):
4242
def _antlr_library(ctx):
4343
output = ctx.actions.declare_directory(ctx.attr.name)
4444

45+
src_path = ctx.file.src.path
46+
47+
# Workaround for Antlr4 bug:
48+
# https://github.com/antlr/antlr4/issues/3138
49+
windows_constraint = ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]
50+
if ctx.target_platform_has_constraint(windows_constraint):
51+
src_path = src_path.replace('/', '\\')
52+
4553
antlr_args = ctx.actions.args()
4654
antlr_args.add("-Dlanguage=Cpp")
4755
antlr_args.add("-no-listener")
4856
antlr_args.add("-visitor")
4957
antlr_args.add("-o", output.path)
5058
antlr_args.add("-package", ctx.attr.package)
51-
antlr_args.add(ctx.file.src)
59+
antlr_args.add(src_path)
5260

5361
# Strip ".g4" extension.
5462
basename = ctx.file.src.basename[:-3]
@@ -98,5 +106,6 @@ antlr_library = rule(
98106
cfg = "exec", # buildifier: disable=attr-cfg
99107
default = Label("//bazel:antlr4_tool"),
100108
),
109+
'_windows_constraint': attr.label(default = '@platforms//os:windows'),
101110
},
102111
)

0 commit comments

Comments
 (0)