Skip to content

Commit 8a19e6b

Browse files
committed
windows fixes
1 parent a5f84ae commit 8a19e6b

File tree

22 files changed

+853
-79
lines changed

22 files changed

+853
-79
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ coverage --deleted_packages=js/private/test/image/non_ascii
3131
# should be last statement in this config so the user configuration is able to overwrite flags from
3232
# this file. See https://bazel.build/configure/best-practices#bazelrc-file.
3333
try-import %workspace%/.aspect/bazelrc/user.bazelrc
34+
try-import %workspace%/.bazelrc.user

.github/workflows/ci.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,14 @@ jobs:
9292
ASPECT_NPM_AUTH_TOKEN: ${{ secrets.ASPECT_NPM_AUTH_TOKEN }}
9393
- id: os
9494
name: Prepare 'os' matrix axis
95-
# Only run MacOS and Windows on main branch (not PRs) to minimize minutes (billed at 10X and 2X respectively)
95+
# Only run MacOS on main branch (not PRs) to minimize minutes (billed at 10X and 2X respectively)
9696
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
9797
run: |
9898
a=( ubuntu )
9999
if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"macos"* ]]; then
100100
a+=( macos )
101101
fi
102-
if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"windows"* ]]; then
103-
a+=( windows )
104-
fi
102+
a+=( windows )
105103
printf -v j '"%s",' "${a[@]}"
106104
echo "res=[${j%,}]" | tee -a $GITHUB_OUTPUT
107105
outputs:
@@ -124,8 +122,6 @@ jobs:
124122
os: ${{ fromJSON(needs.matrix-prep.outputs.os) }}
125123
folder: ${{ fromJSON(needs.matrix-prep.outputs.folder) }}
126124
exclude:
127-
# Exclude Windows default, will opt-in to includes
128-
- os: windows
129125
# Exclude MacOS by default, will opt-in to includes
130126
- os: macos
131127
# Don't run bzlmod smoke test under workspace

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ node_modules/
88
.bazelbsp/
99
.vscode
1010
.DS_Store
11+
.bazelrc.user
1112

1213
# Bazel's MODULE lockfile isn't ready to check in yet as of Bazel 7.1.
1314
# Do allow for it to be created, however, since it gives a performance boost for local development.

MODULE.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ module(
88

99
# Lower-bounds (minimum) versions for direct runtime dependencies.
1010
# Do not bump these unless rules_js requires a newer version to function.
11-
bazel_dep(name = "aspect_bazel_lib", version = "2.14.0")
11+
bazel_dep(name = "aspect_bazel_lib", version = "2.21.0")
1212
bazel_dep(name = "aspect_tools_telemetry", version = "0.2.8")
1313
bazel_dep(name = "bazel_features", version = "1.9.0")
1414
bazel_dep(name = "bazel_skylib", version = "1.5.0")
1515
bazel_dep(name = "platforms", version = "0.0.5")
1616
bazel_dep(name = "rules_nodejs", version = "6.3.0")
17+
bazel_dep(name = "tar.bzl", version = "0.5.5")
1718

1819
tel = use_extension("@aspect_tools_telemetry//:extension.bzl", "telemetry")
1920
use_repo(tel, "aspect_tools_telemetry_report")

e2e/bzlmod/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ assert_contains(
4141
name = "check_styles",
4242
actual = "my.css",
4343
expected = ".box,\n.bar {\n width: 100px;",
44-
# assert_contains currently requires runfiles; needs fixing upstream
45-
target_compatible_with = not_windows,
4644
)
4745

4846
jasmine_bin.jasmine_test(

examples/runfiles/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ js_test(
1212
],
1313
entry_point = "test.js",
1414
tags = ["skip-on-bazel8"],
15+
# Error: could not resolve module aspect_rules_js/examples/runfiles/test_fixture.md
16+
target_compatible_with = select({
17+
"@platforms//os:windows": ["@platforms//:incompatible"],
18+
"//conditions:default": [],
19+
}),
1520
)
1621

1722
# Path of file must start similar to `test_fixture.md` in order to regression-test a

js/private/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package(default_visibility = ["//visibility:public"])
99
exports_files(glob(["*.bzl"]))
1010

1111
exports_files([
12+
"js_binary.bat.tpl",
1213
"js_binary.sh.tpl",
1314
"node_wrapper.bat",
1415
"node_wrapper.sh",

js/private/bash.bzl

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@
88
# NB: If this can be generalized fully in the future and not depend on logf_fatal
99
# then it could be hoisted to bazel-lib where we have other bash snippets.
1010
BASH_INITIALIZE_RUNFILES = r"""
11-
# It helps to determine if we are running on a Windows environment (excludes WSL as it acts like Unix)
12-
case "$(uname -s)" in
13-
CYGWIN*) _IS_WINDOWS=1 ;;
14-
MINGW*) _IS_WINDOWS=1 ;;
15-
MSYS_NT*) _IS_WINDOWS=1 ;;
16-
*) _IS_WINDOWS=0 ;;
17-
esac
18-
19-
# It helps to normalizes paths when running on Windows.
20-
#
21-
# Example:
22-
# C:/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C -> /c/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C
23-
function _normalize_path {
24-
if [ "$_IS_WINDOWS" -eq "1" ]; then
25-
# Apply the followings paths transformations to normalize paths on Windows
26-
# -process driver letter
27-
# -convert path separator
28-
sed -e 's#^\(.\):#/\L\1#' -e 's#\\#/#g' <<<"$1"
29-
else
30-
echo "$1"
31-
fi
32-
return
33-
}
34-
3511
# Set a RUNFILES environment variable to the root of the runfiles tree
3612
# since RUNFILES_DIR is not set by Bazel in all contexts.
3713
# For example, `RUNFILES=/path/to/my_js_binary.sh.runfiles`.
@@ -57,9 +33,9 @@ function _normalize_path {
5733
# Case 6a is handled like case 3.
5834
if [ "${TEST_SRCDIR:-}" ]; then
5935
# Case 4, bazel has identified runfiles for us.
60-
RUNFILES=$(_normalize_path "$TEST_SRCDIR")
36+
RUNFILES=$TEST_SRCDIR
6137
elif [ "${RUNFILES_MANIFEST_FILE:-}" ]; then
62-
RUNFILES=$(_normalize_path "$RUNFILES_MANIFEST_FILE")
38+
RUNFILES=$RUNFILES_MANIFEST_FILE
6339
if [[ "${RUNFILES}" == *.runfiles_manifest ]]; then
6440
# Newer versions of Bazel put the manifest besides the runfiles with the suffix .runfiles_manifest.
6541
# For example, the runfiles directory is named my_binary.runfiles then the manifest is beside the
@@ -105,8 +81,6 @@ else
10581
logf_fatal "RUNFILES environment variable is not set"
10682
exit 1
10783
fi
108-
109-
RUNFILES=$(_normalize_path "$RUNFILES")
11084
fi
11185
if [ "${RUNFILES:0:1}" != "/" ]; then
11286
# Ensure RUNFILES set above is an absolute path. It may be a path relative

js/private/bat.bzl

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
"Windows Batch snippets for js rules"
2+
3+
# TODO: Instead of setting a new RUNFILES env; just set RUNFILES_DIR if it is not set;
4+
# needs testing to know if RUNFILES_DIR is set always set to the same value as RUNFILES
5+
# when it is set.
6+
# Batch snippet to initialize the RUNFILES environment variable.
7+
# Depends on there being a logf_fatal function defined.
8+
# NB: If this can be generalized fully in the future and not depend on logf_fatal
9+
# then it could be hoisted to bazel-lib where we have other batch snippets.
10+
BAT_INITIALIZE_RUNFILES = r"""
11+
rem Initialize RUNFILES environment variable for Windows batch
12+
rem This is the Windows batch equivalent of the bash runfiles initialization
13+
14+
:init_runfiles
15+
rem Set a RUNFILES environment variable to the root of the runfiles tree
16+
rem since RUNFILES_DIR is not set by Bazel in all contexts.
17+
rem For example, `RUNFILES=C:\path\to\my_js_binary.bat.runfiles`.
18+
rem
19+
rem Call this program X. X was generated by a genrule and may be invoked
20+
rem in many ways:
21+
rem 1a) directly by a user, with %0 in the output tree
22+
rem 1b) via 'bazel run' (similar to case 1a)
23+
rem 2) directly by a user, with %0 in X's runfiles
24+
rem 3) by another program Y which has a data dependency on X, with %0 in Y's
25+
rem runfiles
26+
rem 4a) via 'bazel test'
27+
rem 4b) case 3 in the context of a test
28+
rem 5a) by a genrule cmd, with %0 in the output tree
29+
rem 6a) case 3 in the context of a genrule
30+
rem
31+
rem For case 1, %0 will be a regular file, and the runfiles will be
32+
rem at %0.runfiles.
33+
rem For case 2 or 3, %0 will be a symlink to the file seen in case 1.
34+
rem For case 4, %TEST_SRCDIR% should already be set to the runfiles by
35+
rem bazel.
36+
rem Case 5a is handled like case 1.
37+
rem Case 6a is handled like case 3.
38+
39+
if defined TEST_SRCDIR (
40+
rem Case 4, bazel has identified runfiles for us.
41+
set "RUNFILES=%TEST_SRCDIR%"
42+
rem Convert forward slashes to backslashes
43+
set "RUNFILES=!RUNFILES:/=\!"
44+
) else if defined RUNFILES_MANIFEST_FILE (
45+
set "RUNFILES=%RUNFILES_MANIFEST_FILE%"
46+
rem Convert forward slashes to backslashes
47+
set "RUNFILES=!RUNFILES:/=\!"
48+
rem Check if RUNFILES ends with .runfiles_manifest
49+
if "!RUNFILES:~-17!"==".runfiles_manifest" (
50+
rem Newer versions of Bazel put the manifest besides the runfiles with the suffix .runfiles_manifest.
51+
rem For example, the runfiles directory is named my_binary.runfiles then the manifest is beside the
52+
rem runfiles directory and named my_binary.runfiles_manifest
53+
set "RUNFILES=!RUNFILES:~0,-17!"
54+
) else (
55+
rem Check if RUNFILES ends with \MANIFEST
56+
echo !RUNFILES! | findstr /c:"\MANIFEST" >nul
57+
if !errorlevel! equ 0 (
58+
rem Older versions of Bazel put the manifest file named MANIFEST in the runfiles directory
59+
set "RUNFILES=!RUNFILES:\MANIFEST=!"
60+
) else (
61+
call :logf_fatal "Unexpected RUNFILES_MANIFEST_FILE value %RUNFILES_MANIFEST_FILE%"
62+
exit /b 1
63+
)
64+
)
65+
) else (
66+
rem Determine the full path of the current script
67+
set "self=%~f0"
68+
69+
:resolve_runfiles_loop
70+
rem Check if .runfiles directory exists next to the script
71+
if exist "!self!.runfiles" (
72+
set "RUNFILES=!self!.runfiles"
73+
goto :runfiles_found
74+
)
75+
76+
rem Check if we're inside a .runfiles directory
77+
echo !self! | findstr /c:".runfiles\" >nul
78+
if !errorlevel! equ 0 (
79+
rem Extract the runfiles directory path
80+
for /f "tokens=1 delims=" %%a in ('echo !self! ^| findstr /o /c:".runfiles\"') do set "pos_info=%%a"
81+
for /f "tokens=1 delims=:" %%b in ("!pos_info!") do set "pos=%%b"
82+
set /a "end_pos=!pos!+9"
83+
for /f %%c in ('echo !self! ^| findstr /c:".runfiles\"') do (
84+
for /f "tokens=1 delims=\" %%d in ("%%c") do (
85+
set "base_part=%%d"
86+
)
87+
)
88+
rem Find the .runfiles directory by going back from current position
89+
for /f "delims=" %%e in ('echo !self!') do (
90+
set "temp_path=%%e"
91+
for /f "tokens=1,* delims=\" %%f in ("!temp_path!") do (
92+
if "%%g"=="" (
93+
if exist "%%f.runfiles" set "RUNFILES=%%f.runfiles"
94+
) else (
95+
call :extract_runfiles_path "%%e"
96+
)
97+
)
98+
)
99+
rem This is a last resort for case 6b - don't exit the loop yet
100+
)
101+
102+
rem For Windows, we don't need to resolve symlinks like in bash since
103+
rem Windows batch files don't typically use symlinks in the same way
104+
rem If we reach here and haven't found runfiles, we'll fail below
105+
106+
:runfiles_found
107+
if not defined RUNFILES (
108+
call :logf_fatal "RUNFILES environment variable is not set"
109+
exit /b 1
110+
)
111+
112+
rem Convert forward slashes to backslashes
113+
set "RUNFILES=!RUNFILES:/=\!"
114+
)
115+
116+
rem Ensure RUNFILES is an absolute path
117+
echo !RUNFILES! | findstr "^[A-Za-z]:" >nul
118+
if !errorlevel! neq 0 (
119+
rem RUNFILES is not absolute, make it relative to current directory
120+
set "RUNFILES=%CD%\!RUNFILES!"
121+
)
122+
123+
goto :runfiles_init_done
124+
125+
:extract_runfiles_path
126+
set "input_path=%~1"
127+
rem Simple approach to find .runfiles directory in path
128+
for /f "tokens=*" %%a in ('echo %input_path% ^| findstr /c:".runfiles"') do (
129+
set "temp=%%a"
130+
for /f "tokens=1 delims=\" %%b in ('echo !temp! ^| findstr /o /c:".runfiles"') do (
131+
set "match_info=%%b"
132+
for /f "tokens=1 delims=:" %%c in ("!match_info!") do (
133+
set "match_pos=%%c"
134+
set /a "runfiles_end=!match_pos!+8"
135+
set "RUNFILES=!input_path:~0,%runfiles_end%!"
136+
)
137+
)
138+
)
139+
exit /b 0
140+
141+
:runfiles_init_done
142+
"""

0 commit comments

Comments
 (0)