-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add zls toolchain support #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5e54c84
feat: add zls toolchain support
cerisier 929e767
zig_build: propagate shared libraries in the runfiles
cerisier ea25033
Missing dev_dependecy
cerisier 60dbbc0
Fix docs
cerisier f5f46f9
fix
cerisier a94f506
Add missing explicit -lc
cerisier 0a83874
test: add zls build config golden
cerisier 13c6f74
zls: map zig 0.15.2 toolchain
cerisier a6ef995
zls: support zig 0.15 runners
cerisier 324b050
build: drop redundant objc_common deps [agent]
cerisier dda9ee9
zls: address review nits [agent]
cerisier 5eb5307
docs: expand zls completion example [agent]
cerisier 538a082
zls: configure runner cache behavior [agent]
cerisier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,100 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import argparse | ||
| import json | ||
| import urllib.request | ||
|
|
||
|
|
||
| _ZLS_INDEX_URL = "https://builds.zigtools.org/index.json" | ||
|
|
||
| _UNSUPPORTED_VERSIONS = [ | ||
| ] | ||
|
|
||
| _SUPPORTED_PLATFORMS = [ | ||
| "aarch64-linux", | ||
| "aarch64-macos", | ||
| "aarch64-windows", | ||
| "x86_64-linux", | ||
| "x86_64-macos", | ||
| "x86_64-windows"] | ||
|
|
||
|
|
||
| def fetch_zls_versions(url): | ||
| request = urllib.request.Request( | ||
| url, | ||
| headers={"User-Agent": "rules_zig update_zls_versions.py"}, | ||
| ) | ||
| with urllib.request.urlopen(request) as response: | ||
| if response.status != 200: | ||
| raise Exception(f"HTTP error: {response.status}") | ||
| data = response.read() | ||
| return json.loads(data.decode('utf-8')) | ||
|
|
||
|
|
||
| def _parse_semver(version_str): | ||
| """Split a semantic version into its components. | ||
|
|
||
| Raises an error if the version is malformed. | ||
|
|
||
| If the version contains no pre-release component, then a sentinel of | ||
| `0x10FFFF` is returned. The intent is that it sorts higher than any other | ||
| code-point, therefore making versions without pre-release component sort | ||
| higher than this with. | ||
|
|
||
| If the version is the string `master` then it returns a maximum version | ||
| comprising `float("inf")` components and the pre-release sentinel. | ||
|
|
||
| Returns: | ||
| (major, minor, patch, pre_release) | ||
| """ | ||
| max_component = float("inf") | ||
| max_prerelease = chr(0x10FFFF) # Highest valid code point in Unicode | ||
|
|
||
| if version_str == "master": | ||
| return max_component, max_component, max_component, max_prerelease | ||
|
|
||
| pre_version, *_ = version_str.split("+", maxsplit=1) | ||
| main_version, *pre_release = pre_version.split("-", maxsplit=1) | ||
| major, minor, patch = map(int, main_version.split(".")) | ||
|
|
||
| pre_release_segment = pre_release[0] if pre_release else max_prerelease | ||
|
|
||
| return major, minor, patch, pre_release_segment | ||
|
|
||
|
|
||
| def generate_json_content(data, unsupported_versions, supported_platforms): | ||
| content = {} | ||
|
|
||
| for version, platforms in sorted(data.items(), key=lambda x: _parse_semver(x[0]), reverse=True): | ||
| if version in unsupported_versions or version == "master": | ||
| continue | ||
|
|
||
| for platform, info in sorted(platforms.items()): | ||
| if platform not in supported_platforms or not isinstance(info, dict): | ||
| continue | ||
|
|
||
| content.setdefault(version, {})[platform] = { | ||
| "tarball": info["tarball"], | ||
| "shasum": info["shasum"], | ||
| } | ||
|
|
||
| return content | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Generate JSON file for ZLS versions.") | ||
| parser.add_argument("--output", type=argparse.FileType('w'), default='-', help="Output file path or '-' for stdout.") | ||
| parser.add_argument("--url", default=_ZLS_INDEX_URL, help="URL to fetch ZLS versions JSON") | ||
| parser.add_argument("--unsupported-versions", nargs="*", default=_UNSUPPORTED_VERSIONS, help="List of unsupported ZLS versions") | ||
| parser.add_argument("--supported-platforms", nargs="*", default=_SUPPORTED_PLATFORMS, help="List of supported platforms") | ||
| args = parser.parse_args() | ||
|
|
||
| zls_data = fetch_zls_versions(args.url) | ||
| json_content = generate_json_content(zls_data, set(args.unsupported_versions), set(args.supported_platforms)) | ||
|
|
||
| json.dump(json_content, args.output, indent=2) | ||
| args.output.write("\n") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,100 @@ | ||
| load("@bazel_skylib//rules:diff_test.bzl", "diff_test") | ||
| load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
| load("@rules_python//python:defs.bzl", "py_binary") | ||
| load("//zig:defs.bzl", "zig_binary", "zig_library") | ||
| load("//zig/zls:defs.bzl", "zls_completion") | ||
| load("//zig/zls:zls_write_build_config.bzl", "zls_write_build_config") | ||
|
|
||
| zig_library( | ||
| name = "lib", | ||
| main = "main.zig", | ||
| ) | ||
|
|
||
| zls_completion( | ||
| name = "completion", | ||
| testonly = True, | ||
| deps = [":lib"], | ||
| ) | ||
|
|
||
| zig_library( | ||
| name = "leaf", | ||
| import_name = "custom/leaf", | ||
| main = "leaf.zig", | ||
| ) | ||
|
|
||
| zig_library( | ||
| name = "named", | ||
| import_name = "custom/named", | ||
| main = "named.zig", | ||
| ) | ||
|
|
||
| zig_library( | ||
| name = "mid", | ||
| main = "mid.zig", | ||
| deps = [":leaf"], | ||
| ) | ||
|
|
||
| write_file( | ||
| name = "generated_src", | ||
| out = "generated.zig", | ||
| content = ["pub const generated_value = 7;"], | ||
| ) | ||
|
|
||
| zig_library( | ||
| name = "generated", | ||
| main = ":generated_src", | ||
| ) | ||
|
|
||
| zig_library( | ||
| name = "app", | ||
| main = "app.zig", | ||
| deps = [ | ||
| ":generated", | ||
| ":mid", | ||
| ":named", | ||
| "//zig/tests/zls-completion/nested", | ||
| ], | ||
| ) | ||
|
|
||
| zig_binary( | ||
| name = "binary_with_main", | ||
| main = "binary_with_main.zig", | ||
| deps = [":app"], | ||
| ) | ||
|
|
||
| zig_binary( | ||
| name = "binary_from_root_module", | ||
| deps = [":app"], | ||
| ) | ||
|
|
||
| zls_write_build_config( | ||
| name = "golden_build_config", | ||
| testonly = True, | ||
| out = "golden_build_config.json", | ||
| deps = [ | ||
| ":app", | ||
| ":binary_from_root_module", | ||
| ":binary_with_main", | ||
| ], | ||
| ) | ||
|
|
||
| py_binary( | ||
| name = "normalize_zls_build_config", | ||
| srcs = ["normalize_zls_build_config.py"], | ||
| ) | ||
|
|
||
| genrule( | ||
| name = "golden_build_config_normalized", | ||
| testonly = True, | ||
| srcs = [":golden_build_config"], | ||
| outs = ["golden_build_config.normalized.json"], | ||
| cmd = "$(execpath :normalize_zls_build_config) $(location :golden_build_config) $@", | ||
| tools = [":normalize_zls_build_config"], | ||
| ) | ||
|
|
||
| diff_test( | ||
| name = "golden_build_config_test", | ||
| size = "small", | ||
| file1 = "golden_build_config.expected.json", | ||
| file2 = ":golden_build_config_normalized", | ||
| ) |
This file contains hidden or 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,12 @@ | ||
| const generated = @import("generated"); | ||
| const mid = @import("mid"); | ||
| const named = @import("custom/named"); | ||
| const nested = @import("nested/module"); | ||
|
|
||
| pub fn value() i32 { | ||
| return generated.generated_value + mid.value() + @as(i32, @intFromBool(named.enabled)) + nested.value; | ||
| } | ||
|
|
||
| pub fn main() void { | ||
| _ = value(); | ||
| } |
This file contains hidden or 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,5 @@ | ||
| const app = @import("app"); | ||
|
|
||
| pub fn main() void { | ||
| _ = app.value(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.