Skip to content

Commit 1746cdf

Browse files
committed
fix: make stat command cross-platform compatible for macOS CI
- Replace Linux-specific 'stat -c %s' with cross-platform script - macOS uses 'stat -f %z' while Linux uses 'stat -c %s' - Fixes CI failure: 'stat: illegal option -- c' on macOS runners - Maintains compatibility with both GNU/Linux and BSD/macOS stat
1 parent c7e5ebe commit 1746cdf

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

wkg/defs.bzl

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,12 +2692,32 @@ def _wasm_component_metadata_extract_impl(ctx):
26922692
# Extract metadata using separate Bazel-native actions (no shell scripts)
26932693
metadata_output = ctx.actions.declare_file(ctx.attr.name + "_extracted_metadata.json")
26942694

2695-
# Step 1: Get file size using stat (single tool call)
2695+
# Step 1: Get file size using cross-platform approach
26962696
file_size_output = ctx.actions.declare_file(ctx.attr.name + "_file_size.txt")
2697+
2698+
# Create cross-platform script to get file size
2699+
get_size_script = ctx.actions.declare_file(ctx.attr.name + "_get_size.sh")
2700+
ctx.actions.write(
2701+
output = get_size_script,
2702+
content = """#!/bin/bash
2703+
set -euo pipefail
2704+
2705+
# Cross-platform file size detection
2706+
if [[ "$OSTYPE" == "darwin"* ]]; then
2707+
# macOS/BSD stat
2708+
stat -f %z "$1" > "$2"
2709+
else
2710+
# Linux/GNU stat
2711+
stat -c %s "$1" > "$2"
2712+
fi
2713+
""",
2714+
is_executable = True,
2715+
)
2716+
26972717
ctx.actions.run(
2698-
executable = "stat",
2699-
arguments = ["-c", "%s", component_info.path], # Linux format
2700-
inputs = [component_info],
2718+
executable = get_size_script,
2719+
arguments = [component_info.path, file_size_output.path],
2720+
inputs = [component_info, get_size_script],
27012721
outputs = [file_size_output],
27022722
mnemonic = "WasmFileSize",
27032723
progress_message = "Getting component file size",

0 commit comments

Comments
 (0)