Skip to content

Commit bbfbca5

Browse files
author
xryu
committed
Harden Windows bundle runtime detection
1 parent b41baa8 commit bbfbca5

3 files changed

Lines changed: 65 additions & 23 deletions

File tree

.github/workflows/ci.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,34 @@ jobs:
7474
- name: Run tests
7575
run: cargo test --workspace --target ${{ matrix.target }}
7676

77-
- name: Find runtime library
78-
if: matrix.package_bundle
79-
id: find-runtime
77+
- name: Find runtime library (Windows)
78+
if: matrix.package_bundle && contains(matrix.target, 'windows')
79+
id: find-runtime-windows
80+
shell: pwsh
81+
run: |
82+
$runtime = Get-ChildItem "target/${{ matrix.target }}/release/build" -Recurse -Filter "dsview_runtime.dll" -ErrorAction Stop |
83+
Sort-Object FullName |
84+
Select-Object -First 1 -ExpandProperty FullName
85+
if (-not $runtime) {
86+
throw "Windows runtime library was not found under target/${{ matrix.target }}/release/build"
87+
}
88+
"runtime-lib=$runtime" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
89+
90+
- name: Find runtime library (Unix)
91+
if: matrix.package_bundle && !contains(matrix.target, 'windows')
92+
id: find-runtime-unix
8093
shell: bash
8194
run: |
82-
if [[ "${{ matrix.target }}" == *"windows"* ]]; then
83-
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "dsview_runtime.dll" | head -n 1)
84-
elif [[ "${{ matrix.target }}" == *"darwin"* ]] || [[ "${{ matrix.target }}" == *"macos"* ]]; then
85-
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "libdsview_runtime.dylib" | head -n 1)
95+
if [[ "${{ matrix.target }}" == *"darwin"* ]] || [[ "${{ matrix.target }}" == *"macos"* ]]; then
96+
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "libdsview_runtime.dylib" -print -quit)
8697
else
87-
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "libdsview_runtime.so" | head -n 1)
98+
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "libdsview_runtime.so" -print -quit)
99+
fi
100+
if [[ -z "$RUNTIME_LIB" ]]; then
101+
echo "runtime library was not found for ${{ matrix.target }}" >&2
102+
exit 1
88103
fi
89-
echo "runtime-lib=$RUNTIME_LIB" >> $GITHUB_OUTPUT
104+
echo "runtime-lib=$RUNTIME_LIB" >> "$GITHUB_OUTPUT"
90105
91106
- name: Determine executable path
92107
if: matrix.package_bundle
@@ -106,4 +121,4 @@ jobs:
106121
target: ${{ matrix.target }}
107122
version: ${{ steps.version.outputs.version }}
108123
exe-path: ${{ steps.exe-path.outputs.exe }}
109-
runtime-path: ${{ steps.find-runtime.outputs.runtime-lib }}
124+
runtime-path: ${{ contains(matrix.target, 'windows') && steps.find-runtime-windows.outputs.runtime-lib || steps.find-runtime-unix.outputs.runtime-lib }}

.github/workflows/release.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,34 @@ jobs:
7070
- name: Run tests
7171
run: cargo test --workspace --target ${{ matrix.target }}
7272

73-
- name: Find runtime library
74-
if: matrix.package_bundle
75-
id: find-runtime
73+
- name: Find runtime library (Windows)
74+
if: matrix.package_bundle && contains(matrix.target, 'windows')
75+
id: find-runtime-windows
76+
shell: pwsh
77+
run: |
78+
$runtime = Get-ChildItem "target/${{ matrix.target }}/release/build" -Recurse -Filter "dsview_runtime.dll" -ErrorAction Stop |
79+
Sort-Object FullName |
80+
Select-Object -First 1 -ExpandProperty FullName
81+
if (-not $runtime) {
82+
throw "Windows runtime library was not found under target/${{ matrix.target }}/release/build"
83+
}
84+
"runtime-lib=$runtime" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
85+
86+
- name: Find runtime library (Unix)
87+
if: matrix.package_bundle && !contains(matrix.target, 'windows')
88+
id: find-runtime-unix
7689
shell: bash
7790
run: |
78-
if [[ "${{ matrix.target }}" == *"windows"* ]]; then
79-
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "dsview_runtime.dll" | head -n 1)
80-
elif [[ "${{ matrix.target }}" == *"darwin"* ]] || [[ "${{ matrix.target }}" == *"macos"* ]]; then
81-
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "libdsview_runtime.dylib" | head -n 1)
91+
if [[ "${{ matrix.target }}" == *"darwin"* ]] || [[ "${{ matrix.target }}" == *"macos"* ]]; then
92+
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "libdsview_runtime.dylib" -print -quit)
8293
else
83-
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "libdsview_runtime.so" | head -n 1)
94+
RUNTIME_LIB=$(find target/${{ matrix.target }}/release/build/dsview-sys-*/out/source-runtime-build -name "libdsview_runtime.so" -print -quit)
95+
fi
96+
if [[ -z "$RUNTIME_LIB" ]]; then
97+
echo "runtime library was not found for ${{ matrix.target }}" >&2
98+
exit 1
8499
fi
85-
echo "runtime-lib=$RUNTIME_LIB" >> $GITHUB_OUTPUT
100+
echo "runtime-lib=$RUNTIME_LIB" >> "$GITHUB_OUTPUT"
86101
87102
- name: Determine executable path
88103
if: matrix.package_bundle
@@ -102,7 +117,7 @@ jobs:
102117
target: ${{ matrix.target }}
103118
version: ${{ steps.version.outputs.version }}
104119
exe-path: ${{ steps.exe-path.outputs.exe }}
105-
runtime-path: ${{ steps.find-runtime.outputs.runtime-lib }}
120+
runtime-path: ${{ contains(matrix.target, 'windows') && steps.find-runtime-windows.outputs.runtime-lib || steps.find-runtime-unix.outputs.runtime-lib }}
106121
publish-release:
107122
name: publish-release
108123
needs: build-release

tools/package-bundle.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,28 @@ def ensure_exists(path: Path, label: str) -> None:
3434
raise FileNotFoundError(f"{label} not found: {path}")
3535

3636

37+
def ensure_file(path: Path, label: str) -> None:
38+
ensure_exists(path, label)
39+
if not path.is_file():
40+
raise FileNotFoundError(f"{label} is not a file: {path}")
41+
42+
43+
def ensure_directory(path: Path, label: str) -> None:
44+
ensure_exists(path, label)
45+
if not path.is_dir():
46+
raise FileNotFoundError(f"{label} is not a directory: {path}")
47+
48+
3749
def add_file(archive: tarfile.TarFile, source: Path, destination: str) -> None:
3850
archive.add(source, arcname=destination, recursive=False)
3951

4052

4153
def main() -> int:
4254
args = parse_args()
4355

44-
ensure_exists(args.exe, "Executable")
45-
ensure_exists(args.runtime, "Runtime library")
46-
ensure_exists(args.resources, "Resources directory")
56+
ensure_file(args.exe, "Executable")
57+
ensure_file(args.runtime, "Runtime library")
58+
ensure_directory(args.resources, "Resources directory")
4759

4860
archive_root = f"dsview-cli-{args.version}-{args.target}"
4961
exe_name = "dsview-cli.exe" if "windows" in args.target else "dsview-cli"

0 commit comments

Comments
 (0)