From b4ded003214c09164acf05d3d5cfd2e9adb91d0b Mon Sep 17 00:00:00 2001 From: Cameron Martin Date: Mon, 25 Nov 2024 19:52:03 +0000 Subject: [PATCH] ci: Build on windows (#23) This requires a few hacks to avoid hitting the Windows path limit, plus a few generalisations around path names and usage of platform-specific extension traits. --------- Co-authored-by: Grzegorz Lukasik --- .bazelrc | 7 ++++++ .github/workflows/build-release.yml | 36 ++++++++++++++++++++++------- src/bazel.rs | 11 +++++---- src/workspace.rs | 7 +++--- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/.bazelrc b/.bazelrc index aefb7df..9f1e4a0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -6,6 +6,13 @@ common --enable_platform_specific_config build --deleted_packages=fixtures/bzlmod/root,fixtures/simple/output_base/external/bar,fixtures/simple/output_base/external/foo,fixtures/simple/root,fixtures/simple/root/foo query --deleted_packages=fixtures/bzlmod/root,fixtures/simple/output_base/external/bar,fixtures/simple/output_base/external/foo,fixtures/simple/root,fixtures/simple/root/foo +# Test fixtures require runfiles on all platforms +build --enable_runfiles + +# This shortens paths on windows +common:windows --nolegacy_external_runfiles +common:windows --experimental_sibling_repository_layout + build:ci --bes_results_url=https://bazel-lsp.buildbuddy.io/invocation/ build:ci --bes_backend=grpcs://bazel-lsp.buildbuddy.io # Do not wait for BES upload to finish to avoid failing build if BES is not available. diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 33bbac4..54ec216 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -16,9 +16,9 @@ jobs: - name: linux-amd64 runs-on: ubuntu-20.04 extension: "" - # - name: windows-amd64 - # runs-on: windows-2019 - # extension: .exe + - name: windows-amd64 + runs-on: windows-2019 + extension: .exe - name: osx-amd64 runs-on: macos-13 extension: "" @@ -29,27 +29,47 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up bazelrc + - name: Set up buildbuddy env: BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }} run: | echo "build:ci --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" >> ~/.bazelrc - echo "startup --output_base=$RUNNER_TEMP/.bazel/output_base" >> ~/.bazelrc + shell: bash + - name: Set up output base + run: | + OUTPUT_BASE=$RUNNER_TEMP/.bazel/output_base + echo "startup --output_base=$OUTPUT_BASE" >> ~/.bazelrc + echo "OUTPUT_BASE=$OUTPUT_BASE" >> "$GITHUB_ENV" + shell: bash + if: runner.os != 'Windows' + - name: Set up output base + run: | + OUTPUT_BASE=C:/b + echo "startup --output_base=$OUTPUT_BASE" >> ~/.bazelrc + echo "OUTPUT_BASE=$OUTPUT_BASE" >> "$GITHUB_ENV" + shell: bash + if: runner.os == 'Windows' - uses: actions/cache@v4 with: path: | - ${{ runner.temp }}/.bazel/output_base/external + ${{ env.OUTPUT_BASE }}/external key: bazel-${{ matrix.target.name }}-${{ github.ref }} restore-keys: bazel-${{ matrix.target.name }}-refs/heads/master - - name: Build & Test + - name: Build & Test (bash) run: | INVOCATION_ID="$(uuidgen)" echo "[View on BuildBuddy](https://bazel-lsp.buildbuddy.io/invocation/$INVOCATION_ID)" >> $GITHUB_STEP_SUMMARY bazel test //... -c opt --config=ci --invocation_id="$INVOCATION_ID" + if: runner.os != 'Windows' + - name: Build & Test (powershell) + run: | + $InvocationId = New-Guid + bazel test //... -c opt --config=ci --invocation_id="$InvocationId" + if: runner.os == 'Windows' - uses: actions/upload-artifact@v4 with: - name: bazel-lsp-${{ matrix.target.name }}${{ matrix.target.extension }} + name: bazel-lsp-${{ matrix.target.name }} path: bazel-bin/bazel-lsp${{ matrix.target.extension }} release: name: Release diff --git a/src/bazel.rs b/src/bazel.rs index bd1899d..def2898 100644 --- a/src/bazel.rs +++ b/src/bazel.rs @@ -896,6 +896,7 @@ impl LspContext for BazelContext { #[cfg(test)] mod tests { use std::path::PathBuf; + use lsp_types::Url; use lsp_types::CompletionItemKind; use serde_json::json; @@ -923,7 +924,7 @@ mod tests { assert_eq!( url, - LspUrl::File(fixture.external_dir("foo").join("foo.bzl")) + Url::from_file_path(fixture.external_dir("foo").join("foo.bzl")).unwrap().try_into()? ); Ok(()) @@ -942,7 +943,7 @@ mod tests { assert_eq!( url, - LspUrl::File(fixture.external_dir("bar").join("bar.bzl")) + Url::from_file_path(fixture.external_dir("bar").join("bar.bzl")).unwrap().try_into()? ); Ok(()) @@ -961,7 +962,7 @@ mod tests { assert_eq!( url, - LspUrl::File(fixture.external_dir("foo").join("foo.bzl")) + Url::from_file_path(fixture.external_dir("foo").join("foo.bzl")).unwrap().try_into()? ); Ok(()) @@ -989,12 +990,12 @@ mod tests { assert_eq!( url, - LspUrl::File( + Url::from_file_path( fixture .external_dir("rules_rust~0.36.2") .join("rust") .join("defs.bzl") - ) + ).unwrap().try_into()? ); assert_eq!(context.client.profile.borrow().dump_repo_mapping, 1); diff --git a/src/workspace.rs b/src/workspace.rs index a5ef390..0c17815 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -1,7 +1,6 @@ use std::{ borrow::Cow, io, - os::unix::ffi::OsStrExt, path::{Path, PathBuf}, }; @@ -42,8 +41,10 @@ impl BazelWorkspace { }), external_output_base: PathBuf::from(info.output_base).join("external"), query_output_base: if let Some(output_base) = query_output_base { - let hash = - digest::digest(&digest::SHA256, output_base.as_ref().as_os_str().as_bytes()); + let hash = digest::digest( + &digest::SHA256, + output_base.as_ref().as_os_str().as_encoded_bytes(), + ); let hash_hex = hex::encode(&hash); Some(output_base.as_ref().join(hash_hex)) } else {