Skip to content

Commit c57c014

Browse files
committed
Use flex and bison directly instead from toolchain.
The flex toolchain from rules_{bison,flex} do not have a version that works on Windows. Using these directly simplifies things as well. Fixes #2435
1 parent a0a8d8e commit c57c014

9 files changed

Lines changed: 31 additions & 73 deletions

File tree

.github/workflows/verible-ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ jobs:
397397
- name: Install dependencies
398398
run: |
399399
choco install bazel --force --version=7.6.1
400-
choco install winflexbison3
401400
choco install llvm --allow-downgrade --version=20.1.4
402401
403402
- name: Debug bazel directory settings

MODULE.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ module(
55

66
bazel_dep(name = "abseil-cpp", version = "20250814.1")
77
bazel_dep(name = "bazel_skylib", version = "1.8.1")
8+
bazel_dep(name = "bison", version = "3.8.2.bcr.5")
9+
bazel_dep(name = "flex", version = "2.6.4.bcr.5")
810
bazel_dep(name = "nlohmann_json", version = "3.12.0.bcr.1")
911
bazel_dep(name = "platforms", version = "1.0.0")
1012
bazel_dep(name = "protobuf", version = "31.0-rc2")
1113
bazel_dep(name = "re2", version = "2024-07-02.bcr.1")
12-
bazel_dep(name = "rules_bison", version = "0.4.bcr.1")
1314
bazel_dep(name = "rules_cc", version = "0.2.16")
14-
bazel_dep(name = "rules_flex", version = "0.4.1")
1515
bazel_dep(name = "rules_license", version = "1.0.0")
16-
bazel_dep(name = "rules_m4", version = "0.2.3")
1716
bazel_dep(name = "rules_shell", version = "0.8.0")
1817
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
1918

README.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,12 @@ instead of default `gold` linker).
201201
bazel build -c opt --config=create_static_linked_executables //...
202202
```
203203

204-
### Optionally using local flex/bison for build
205-
206-
Flex and Bison, that are needed for the parser generation, are compiled as part
207-
of the build process. But if for any reason you want or need local tools (e.g.
208-
if you encounter a compile problem with them - please file a bug then)
209-
can choose so by adding `--//bazel:use_local_flex_bison` to your bazel
210-
command line:
211-
212-
```bash
213-
# Also append the option '--//bazel:use_local_flex_bison' to test/install commands
214-
bazel build -c opt --//bazel:use_local_flex_bison //...
215-
```
216-
217204
### Building on Windows
218205

219-
Building on Windows requires LLVM, WinFlexBison 3 and Git-bash to be installed. Using package manager [chocolatey], this can be done with
206+
Building on Windows requires LLVM and Git-bash to be installed. Using package manager [chocolatey], this can be done with
220207

221208
```powershell
222-
choco install git llvm winflexbison3
209+
choco install git llvm
223210
```
224211

225212
Bazel may also require environment variable to use git-bash and LLVM, on powershell

bazel/BUILD

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ package(
1313
features = ["layering_check"],
1414
)
1515

16-
cc_library(
17-
name = "flex",
18-
deps = [
19-
"@rules_flex//flex:current_flex_toolchain", # For FlexLexer.h
20-
],
21-
)
22-
2316
exports_files([
2417
"bison.bzl",
2518
"flex.bzl",
@@ -30,11 +23,7 @@ exports_files([
3023
bool_flag(
3124
name = "use_local_flex_bison",
3225
build_setting_default = False,
33-
)
34-
35-
config_setting(
36-
name = "use_local_flex_bison_enabled",
37-
flag_values = {":use_local_flex_bison": "true"},
26+
deprecation = "This flag is not doing anything anymore",
3827
)
3928

4029
bool_flag(

bazel/bison.bzl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
"""Bazel rule to run bison toolchain
16+
"""Bazel rule to run bison
1717
"""
1818

19+
load("@bison//:bison.bzl", "bison")
20+
1921
# Adapter rule around the @rules_bison toolchain.
2022
def genyacc(
2123
name,
@@ -26,21 +28,13 @@ def genyacc(
2628
extra_outs = []):
2729
"""Build rule for generating C or C++ sources with Bison.
2830
"""
29-
native.genrule(
31+
32+
bison(
3033
name = name,
3134
srcs = [src],
3235
outs = [header_out, source_out] + extra_outs,
33-
cmd = select({
34-
"//bazel:use_local_flex_bison_enabled": "bison --defines=$(location " + header_out + ") --output-file=$(location " + source_out + ") " + " ".join(extra_options) + " $<",
35-
"@platforms//os:windows": "win_bison.exe --defines=$(location " + header_out + ") --output-file=$(location " + source_out + ") " + " ".join(extra_options) + " $<",
36-
"//conditions:default": "M4=$(M4) $(BISON) --defines=$(location " + header_out + ") --output-file=$(location " + source_out + ") " + " ".join(extra_options) + " $<",
37-
}),
38-
toolchains = select({
39-
"//bazel:use_local_flex_bison_enabled": [],
40-
"@platforms//os:windows": [],
41-
"//conditions:default": [
42-
"@rules_bison//bison:current_bison_toolchain",
43-
"@rules_m4//m4:current_m4_toolchain",
44-
],
45-
}),
36+
args = [
37+
"--output-file=$(location " + source_out + ")",
38+
"--defines=$(location " + header_out + ")",
39+
] + extra_options + ["$(location " + src + ")"],
4640
)

bazel/flex.bzl

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,21 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
"""Bazel rule to run flex toolchain
16+
"""Bazel rule to run flex
1717
"""
1818

19+
load("@flex//:flex.bzl", "flex")
20+
1921
# Adapter rule around the @rules_flex toolchain.
2022
def genlex(name, src, out):
2123
"""Generate C/C++ language source from lex file using Flex
2224
"""
23-
native.genrule(
25+
flex(
2426
name = name,
2527
srcs = [src],
2628
outs = [out],
27-
cmd = select({
28-
"//bazel:use_local_flex_bison_enabled": "flex --outfile=$@ $<",
29-
"@platforms//os:windows": "win_flex.exe --outfile=$@ $<",
30-
"//conditions:default": "M4=$(M4) $(FLEX) --outfile=$@ $<",
31-
}),
32-
toolchains = select({
33-
"//bazel:use_local_flex_bison_enabled": [],
34-
"@platforms//os:windows": [],
35-
"//conditions:default": [
36-
"@rules_flex//flex:current_flex_toolchain",
37-
"@rules_m4//m4:current_m4_toolchain",
38-
],
39-
}),
29+
args = [
30+
"--outfile=$(location " + out + ")",
31+
"$(location " + src + ")",
32+
],
4033
)

shell.nix

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
let
77
verible_used_stdenv = pkgs.stdenv;
88
#verible_used_stdenv = pkgs.gcc15Stdenv;
9-
#verible_used_stdenv = pkgs.clang19Stdenv;
9+
#verible_used_stdenv = pkgs.llvmPackages_21.stdenv;
10+
bazel = pkgs.bazel_7;
1011
in
1112
verible_used_stdenv.mkDerivation {
1213
name = "verible-build-environment";
1314
buildInputs = with pkgs;
1415
[
15-
bazel_7
16+
bazel
1617
git
1718

1819
# For scripts used inside bzl rules and tests
@@ -26,10 +27,6 @@ verible_used_stdenv.mkDerivation {
2627
# To manually run export_json_examples
2728
python3Packages.anytree
2829

29-
# For using --//bazel:use_local_flex_bison if desired
30-
flex
31-
bison
32-
3330
# To build vscode vsix package
3431
nodejs
3532

@@ -46,5 +43,7 @@ verible_used_stdenv.mkDerivation {
4643
4744
# Last version that current github CI supports.
4845
export CLANG_FORMAT=${pkgs.llvmPackages_18.clang-tools}/bin/clang-format
46+
47+
export USE_BAZEL_VERSION=${bazel.version}
4948
'';
5049
}

verible/common/analysis/BUILD

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ package(
1212
"//verible/verilog/tools/lint:__subpackages__",
1313
"//verible/verilog/tools/ls:__subpackages__",
1414
],
15-
# Not yet enabled, lexer does not find FlexLexer.h
16-
#features = ["layering_check"],
15+
features = ["layering_check"],
1716
)
1817

1918
cc_library(
@@ -70,13 +69,13 @@ cc_library(
7069
"//conditions:default": ["-Wno-implicit-fallthrough"],
7170
}),
7271
deps = [
73-
"//bazel:flex",
7472
"//verible/common/lexer:flex-lexer-adapter",
7573
"//verible/common/lexer:token-stream-adapter",
7674
"//verible/common/text:token-info",
7775
"//verible/common/text:token-stream-view",
7876
"//verible/common/util:iterator-range",
7977
"//verible/common/util:logging",
78+
"@flex//:headers",
8079
],
8180
)
8281

verible/verilog/parser/BUILD

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ package(
1414
default_visibility = [
1515
"//verible/verilog:__subpackages__",
1616
],
17-
# Not yet enabled, lexer does not find FlexLexer.h
18-
#features = ["layering_check"],
17+
features = ["layering_check"],
1918
)
2019

2120
genlex(
@@ -39,9 +38,9 @@ cc_library(
3938
}),
4039
deps = [
4140
":verilog-token-enum",
42-
"//bazel:flex",
4341
"//verible/common/lexer:flex-lexer-adapter",
4442
"//verible/common/text:token-info",
43+
"@flex//:headers",
4544
],
4645
)
4746

0 commit comments

Comments
 (0)