-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for win_flex_bison on Windows
- Loading branch information
Showing
5 changed files
with
200 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
load("@com_google_verible//bazel:win_flex_bison.bzl", "win_bison_toolchain", "win_flex_toolchain") | ||
|
||
filegroup( | ||
name = "win_flex", | ||
srcs = ["win_flex.exe"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
filegroup( | ||
name = "flex_lexer_h", | ||
srcs = ["FlexLexer.h"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
filegroup( | ||
name = "win_bison", | ||
srcs = ["win_bison.exe"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
win_flex_toolchain( | ||
name = "flex", | ||
flex_lexer_h = ":flex_lexer_h", | ||
flex_tool = ":win_flex", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
toolchain( | ||
name = "flex_toolchain", | ||
exec_compatible_with = ["@platforms//os:windows"], | ||
target_compatible_with = ["@platforms//os:windows"], | ||
toolchain = ":flex", | ||
toolchain_type = "@rules_flex//flex:toolchain_type", | ||
) | ||
|
||
win_bison_toolchain( | ||
name = "bison", | ||
bison_tool = ":win_bison", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
toolchain( | ||
name = "bison_toolchain", | ||
exec_compatible_with = ["@platforms//os:windows"], | ||
target_compatible_with = ["@platforms//os:windows"], | ||
toolchain = ":bison", | ||
toolchain_type = "@rules_bison//bison:toolchain_type", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# -*- Python -*- | ||
# Copyright 2021 The Verible Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Bazel rule to run flex/bison on Windows | ||
""" | ||
|
||
# buildifier: disable=provider-params | ||
FlexToolchainInfo = provider( | ||
fields = [ | ||
"all_files", | ||
"flex_tool", | ||
"flex_lexer_h", | ||
], | ||
) | ||
|
||
def _win_flex_toolchain_impl(ctx): | ||
flex_runfiles = ctx.attr.flex_tool[DefaultInfo].default_runfiles.files | ||
|
||
return platform_common.ToolchainInfo( | ||
flex_toolchain = FlexToolchainInfo( | ||
all_files = depset( | ||
direct = [ctx.executable.flex_tool], | ||
transitive = [flex_runfiles], | ||
), | ||
flex_tool = ctx.attr.flex_tool.files_to_run, | ||
flex_lexer_h = ctx.file.flex_lexer_h, | ||
), | ||
) | ||
|
||
win_flex_toolchain = rule( | ||
_win_flex_toolchain_impl, | ||
attrs = { | ||
"flex_tool": attr.label( | ||
mandatory = True, | ||
executable = True, | ||
cfg = "host", | ||
), | ||
"flex_lexer_h": attr.label( | ||
mandatory = True, | ||
allow_single_file = [".h"], | ||
), | ||
}, | ||
) | ||
|
||
# buildifier: disable=provider-params | ||
BisonToolchainInfo = provider( | ||
fields = [ | ||
"all_files", | ||
"bison_tool", | ||
], | ||
) | ||
|
||
def _win_bison_toolchain_impl(ctx): | ||
bison_runfiles = ctx.attr.bison_tool[DefaultInfo].default_runfiles.files | ||
|
||
return platform_common.ToolchainInfo( | ||
bison_toolchain = BisonToolchainInfo( | ||
all_files = depset( | ||
direct = [ctx.executable.bison_tool], | ||
transitive = [bison_runfiles], | ||
), | ||
bison_tool = ctx.attr.bison_tool.files_to_run, | ||
), | ||
) | ||
|
||
win_bison_toolchain = rule( | ||
_win_bison_toolchain_impl, | ||
attrs = { | ||
"bison_tool": attr.label( | ||
mandatory = True, | ||
executable = True, | ||
cfg = "host", | ||
), | ||
}, | ||
) | ||
|
||
def _remote_win_flex_bison(repository_ctx): | ||
repository_ctx.download_and_extract( | ||
url = repository_ctx.attr.url, | ||
sha256 = repository_ctx.attr.sha256, | ||
) | ||
|
||
repository_ctx.symlink( | ||
Label("@com_google_verible//bazel:win_flex_bison.BUILD"), | ||
"BUILD.bazel", | ||
) | ||
|
||
remote_win_flex_bison = repository_rule( | ||
implementation = _remote_win_flex_bison, | ||
local = True, | ||
attrs = { | ||
"url": attr.string(mandatory = True), | ||
"sha256": attr.string(default = ""), | ||
}, | ||
) | ||
|
||
def win_flex_configure(name, url, sha256 = ""): | ||
remote_win_flex_bison( | ||
name = name, | ||
url = url, | ||
sha256 = sha256, | ||
) | ||
|
||
native.register_toolchains( | ||
"@" + name + "//:flex_toolchain", | ||
"@" + name + "//:bison_toolchain", | ||
) |