Skip to content

Commit

Permalink
ci: Build on windows (#23)
Browse files Browse the repository at this point in the history
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 <hauserx@gmail.com>
  • Loading branch information
cameron-martin and hauserx authored Nov 25, 2024
1 parent 2f2e5f4 commit b4ded00
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
36 changes: 28 additions & 8 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/bazel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ impl<Client: BazelClient> LspContext for BazelContext<Client> {
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use lsp_types::Url;

use lsp_types::CompletionItemKind;
use serde_json::json;
Expand Down Expand Up @@ -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(())
Expand All @@ -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(())
Expand All @@ -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(())
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
borrow::Cow,
io,
os::unix::ffi::OsStrExt,
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b4ded00

Please sign in to comment.