Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ query --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig

build --experimental_convenience_symlinks=ignore

build --@rules_rust//rust/toolchain/channel=nightly

build --@rules_rust//:rustfmt.toml=//:rustfmt.toml
build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build --output_groups=+rustfmt_checks
Expand All @@ -21,9 +19,14 @@ build --incompatible_strict_action_env

test --test_output=errors

build --experimental_convenience_symlinks=normal

build:linux --sandbox_add_mount_pair=/tmp
build:linux --incompatible_enable_cc_toolchain_resolution
build:linux --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:linux --extra_toolchains @zig_sdk//toolchain:linux_arm64_gnu.2.17,@zig_sdk//toolchain:linux_amd64_gnu.2.17

build:windows --nolegacy_external_runfiles

build --incompatible_enable_proto_toolchain_resolution=true
build --@protobuf//bazel/toolchains:prefer_prebuilt_protoc=True
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ jobs:
- uses: actions/checkout@v3
- name: Prepare for build
run: |
echo 'import %workspace%/bazel/remote-cache.bazelrc' >>.bazelrc
echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" >>.bazelrc
if [[ -n "$BUILDBUDDY_API_KEY" ]]; then
echo 'import %workspace%/bazel/remote-cache.bazelrc' >>.bazelrc
echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" >>.bazelrc
fi
echo "startup --output_user_root=C:/b" >>.bazelrc
echo "startup --windows_enable_symlinks" >>.bazelrc
mkdir -p editors/code/dist
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ jobs:
- uses: actions/checkout@v3
- name: Prepare for build
run: |
echo 'import %workspace%/bazel/remote-cache.bazelrc' >>.bazelrc
echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" >>.bazelrc
if [[ -n "$BUILDBUDDY_API_KEY" ]]; then
echo 'import %workspace%/bazel/remote-cache.bazelrc' >>.bazelrc
echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" >>.bazelrc
fi
echo "startup --output_user_root=C:/b" >>.bazelrc
echo "startup --windows_enable_symlinks" >>.bazelrc
mkdir -p editors/code/dist
Expand Down
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_rust//proto/prost:defs.bzl", "rust_prost_toolchain")
load("@rules_rust//rust:defs.bzl", "rust_library_group")
load("@rules_rust_prost//:defs.bzl", "rust_prost_toolchain")

exports_files(["rustfmt.toml"])

Expand Down Expand Up @@ -30,5 +30,5 @@ rust_prost_toolchain(
toolchain(
name = "prost_toolchain",
toolchain = "prost_toolchain_impl",
toolchain_type = "@rules_rust//proto/prost:toolchain_type",
toolchain_type = "@rules_rust_prost//:toolchain_type",
)
14 changes: 8 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ bazel_dep(name = "aspect_bazel_lib", version = "2.9.4")
bazel_dep(name = "aspect_rules_js", version = "2.1.1")
bazel_dep(name = "aspect_rules_swc", version = "2.0.1")
bazel_dep(name = "aspect_rules_ts", version = "3.3.1")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "hermetic_cc_toolchain", version = "3.1.1")
bazel_dep(name = "protobuf", version = "29.0")
bazel_dep(name = "rules_proto", version = "7.0.2")
bazel_dep(name = "rules_rust", version = "0.53.0")
bazel_dep(name = "protobuf", version = "33.4")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_rust", version = "0.71.3")
bazel_dep(name = "rules_rust_prost", version = "0.71.3")

zig_toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains")
use_repo(zig_toolchains, "zig_sdk")
Expand All @@ -17,14 +18,14 @@ rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = "2021",
extra_target_triples = ["aarch64-unknown-linux-gnu"],
versions = ["nightly/2023-12-06"],
versions = ["1.86.0"],
)
use_repo(rust, "rust_toolchains")

register_toolchains("@rust_toolchains//:all")

crate = use_extension(
"@rules_rust//crate_universe:extension.bzl",
"@rules_rust//crate_universe:extensions.bzl",
"crate",
)
crate.from_cargo(
Expand All @@ -47,6 +48,7 @@ crate.from_cargo(
],
)
use_repo(crate, "crates")

crate.annotation(
crate = "protoc-gen-prost",
gen_binaries = ["protoc-gen-prost"],
Expand Down
12,321 changes: 2,263 additions & 10,058 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions bazel/remote-cache.bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
build --experimental_convenience_symlinks=normal

build --bes_results_url=https://starpls.buildbuddy.io/invocation/
build --bes_backend=grpcs://starpls.buildbuddy.io
build --remote_cache=grpcs://starpls.buildbuddy.io
Expand Down
6 changes: 4 additions & 2 deletions bazel/setup-ci.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash
echo 'import %workspace%/bazel/remote-cache.bazelrc' >>.bazelrc
echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" >>.bazelrc
if [[ -n "$BUILDBUDDY_API_KEY" ]]; then
echo 'import %workspace%/bazel/remote-cache.bazelrc' >>.bazelrc
echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" >>.bazelrc
fi
7 changes: 2 additions & 5 deletions crates/starpls/src/bazel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ impl BazelContext {
// Check if bzlmod is enabled for the current workspace.
let bzlmod_enabled = {
// bzlmod is enabled by default for Bazel versions 7 and later.
// TODO(withered-magic): Just hardcoding this for now since I'm lazy to parse the actual versions.
// This should last us pretty long since Bazel 9 isn't anywhere on the horizon.
let bzlmod_enabled_by_default = ["development", "release 7", "release 8", "release 9"]
.iter()
.any(|release| info.release.starts_with(release));
// Bazel 6 is the only remaining supported version that we do not enable bzlmod by default for.
let bzlmod_enabled_by_default = !info.release.starts_with("release 6");

if bzlmod_enabled_by_default {
info!("Bazel 7 or later detected");
Expand Down
35 changes: 17 additions & 18 deletions crates/starpls/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ impl DefaultFileLoader {
package
} else {
root.join(label.package())
}
.join(label.target());
};

Ok(Some(ResolvedLabel {
resolved_path,
Expand Down Expand Up @@ -363,7 +362,7 @@ impl DefaultFileLoader {
Ok((file_id, contents))
}

fn repo_for_path<'a>(&'a self, path: &'a Path) -> Option<&str> {
fn repo_for_path<'a>(&'a self, path: &'a Path) -> Option<&'a str> {
match path.strip_prefix(&self.external_output_base) {
Ok(stripped) => stripped
.components()
Expand Down Expand Up @@ -399,28 +398,28 @@ impl FileLoader for DefaultFileLoader {
};

let resolved_label = try_opt!(self.resolve_label(&label, from)?);
let res = if fs::metadata(&resolved_label.resolved_path)
let maybe_file_path = resolved_label.resolved_path.join(label.target());
let res = if fs::metadata(&maybe_file_path)
.ok()
.map(|metadata| metadata.is_file())
.unwrap_or_default()
{
ResolvedPath::Source {
path: resolved_label.resolved_path,
path: maybe_file_path,
}
} else {
if label.target().is_empty() {
return Ok(None);
}

let parent = try_opt!(resolved_label.resolved_path.parent());
let build_file = try_opt!(fs::read_dir(parent)
let build_file = try_opt!(fs::read_dir(&resolved_label.resolved_path)
.into_iter()
.flat_map(|entries| entries.into_iter())
.find_map(|entry| match entry.ok()?.file_name().to_str()? {
file_name @ ("BUILD" | "BUILD.bazel") => Some(file_name.to_string()),
_ => None,
}));
let path = parent.join(build_file);
let path = resolved_label.resolved_path.join(build_file);

// If we've already interned this file, then simply return the file id.
let (build_file, contents) =
Expand Down Expand Up @@ -464,16 +463,16 @@ impl FileLoader for DefaultFileLoader {
}

let repo_kind = label.kind();
let (resolved_path, canonical_repo) = match self
.read_cache_result(&repo_kind, path, from)
{
Some(path) => (path, None),
None => {
let res = try_opt!(self.resolve_label(&label, from)?);
self.record_cache_result(&repo_kind, path, from, res.resolved_path.clone());
(res.resolved_path, res.canonical_repo)
}
};
let (resolved_path, canonical_repo) =
match self.read_cache_result(&repo_kind, path, from) {
Some(path) => (path, None),
None => {
let res = try_opt!(self.resolve_label(&label, from)?);
let resolved_path = res.resolved_path.join(label.target());
self.record_cache_result(&repo_kind, path, from, resolved_path.clone());
(resolved_path, res.canonical_repo)
}
};

let is_external = !resolved_path.starts_with(&self.workspace);
(
Expand Down
2 changes: 1 addition & 1 deletion crates/starpls_bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_rust//proto/prost:defs.bzl", "rust_prost_library")
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("@rules_rust_prost//:defs.bzl", "rust_prost_library")

package(default_visibility = ["//visibility:public"])

Expand Down
2 changes: 2 additions & 0 deletions crates/starpls_bazel/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub enum AttributeKind {
LabelKeyedStringDict,
#[serde(rename = "List of Labels")]
LabelList,
#[serde(rename = "Dictionary mapping strings to lists of labels")]
LabelListDict,
// TODO(withered-magic): Add a `rename`.
Output,
#[serde(rename = "List of Outputs")]
Expand Down
4 changes: 2 additions & 2 deletions crates/starpls_bazel/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Label<'a> {
}

impl<'a> Label<'a> {
pub fn parse(input: &'a str) -> ParseResult {
pub fn parse(input: &'a str) -> ParseResult<'a> {
Parser {
chars: input.chars(),
pos: 0,
Expand Down Expand Up @@ -134,7 +134,7 @@ struct Parser<'a, 'b> {
label: Label<'a>,
}

impl<'a, 'b> Parser<'a, 'b> {
impl<'a> Parser<'a, '_> {
fn parse(mut self) -> ParseResult<'a> {
match self.parse_full() {
Ok(_) => Ok(self.label),
Expand Down
2 changes: 1 addition & 1 deletion crates/starpls_hir/src/def/codeflow/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct CodeFlowGraphPrettyCtx<'a> {
indent: String,
}

impl<'a> CodeFlowGraphPrettyCtx<'a> {
impl CodeFlowGraphPrettyCtx<'_> {
fn pretty_print(mut self) -> String {
wln!(&mut self.result, "def main():");
self.push_indent_level();
Expand Down
2 changes: 1 addition & 1 deletion crates/starpls_hir/src/def/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct LoweringContext<'a> {
source_map: ModuleSourceMap,
}

impl<'a> LoweringContext<'a> {
impl LoweringContext<'_> {
fn lower(mut self, syntax: ast::Module) -> (Module, ModuleSourceMap) {
let line_index = line_index(self.db, self.file);
self.module.type_ignore_comment_lines = syntax
Expand Down
2 changes: 1 addition & 1 deletion crates/starpls_hir/src/def/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<'a> Resolver<'a> {
pub(crate) fn resolve_name(
&'a self,
name: &'a Name,
) -> Option<(ExecutionScopeId, impl Iterator<Item = SymbolDef<'a>> + '_)> {
) -> Option<(ExecutionScopeId, impl Iterator<Item = SymbolDef<'a>> + 'a)> {
let mut defs = self
.scopes_with_id()
.filter_map(move |(scope_id, scope)| {
Expand Down
5 changes: 3 additions & 2 deletions crates/starpls_hir/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct DisplayWithDbWrapper<'a, T: DisplayWithDb + ?Sized> {
alt: bool,
}

impl<'a, T: DisplayWithDb> DisplayWithDbWrapper<'a, T> {
impl<T: DisplayWithDb> DisplayWithDbWrapper<'_, T> {
pub fn alt(self) -> Self {
Self {
db: self.db,
Expand All @@ -64,7 +64,7 @@ impl<'a, T: DisplayWithDb> DisplayWithDbWrapper<'a, T> {
}
}

impl<'a, T: DisplayWithDb> fmt::Display for DisplayWithDbWrapper<'a, T> {
impl<T: DisplayWithDb> fmt::Display for DisplayWithDbWrapper<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.alt {
self.item.fmt_alt(self.db, f)
Expand Down Expand Up @@ -99,6 +99,7 @@ impl DisplayWithDb for TyKind {
let text = match self {
TyKind::Unbound => "Unbound",
TyKind::Unknown => "Unknown",
TyKind::EmptyUnspecified => "EmptyUnspecified",
TyKind::Any => "Any",
TyKind::Never => "Never",
TyKind::None => "None",
Expand Down
Loading