Skip to content

Commit 1cfdc8a

Browse files
author
codethinki
committed
optimizing (hopefully)
1 parent e2cb643 commit 1cfdc8a

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

.github/workflows/run-example.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ on:
2121
type: string
2222

2323
env:
24-
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
24+
# VCPKG_ROOT is NOT set here globally to allow container ENV to take precedence on Linux.
25+
# We will set it dynamically in the "Setup Vcpkg" step if it's missing.
2526
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg_cache
2627

2728
jobs:
@@ -78,9 +79,27 @@ jobs:
7879
- name: Setup Vcpkg
7980
shell: bash
8081
run: |
82+
# 1. Check if VCPKG_ROOT is already set (e.g. by Docker container)
83+
if [ -n "$VCPKG_ROOT" ]; then
84+
echo "VCPKG_ROOT is already set to: $VCPKG_ROOT"
85+
if [ -d "$VCPKG_ROOT" ]; then
86+
echo "Vcpkg directory exists. Using: $VCPKG_ROOT"
87+
# No action needed, env var is already present in this shell.
88+
# To be safe for subsequent steps, we re-export it to GITHUB_ENV if it wasn't there (it is via Docker ENV, but good practice)
89+
echo "VCPKG_ROOT=$VCPKG_ROOT" >> $GITHUB_ENV
90+
exit 0
91+
else
92+
echo "Warning: VCPKG_ROOT is set but directory missing. Falling back to install."
93+
fi
94+
fi
95+
96+
# 2. Check for VCPKG_INSTALLATION_ROOT (GitHub Actions default sometimes)
8197
if [ -n "$VCPKG_INSTALLATION_ROOT" ] && [ -d "$VCPKG_INSTALLATION_ROOT" ]; then
98+
echo "Found VCPKG_INSTALLATION_ROOT: $VCPKG_INSTALLATION_ROOT"
8299
echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> $GITHUB_ENV
83100
else
101+
# 3. Fallback: Clone and Bootstrap locally
102+
echo "Vcpkg not found. Installing to workspace."
84103
git clone https://github.com/microsoft/vcpkg.git "$GITHUB_WORKSPACE/vcpkg"
85104
if [[ "$RUNNER_OS" == "Windows" ]]; then
86105
"$GITHUB_WORKSPACE/vcpkg/bootstrap-vcpkg.bat"

docker/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,15 @@ RUN pacman -Sy --noconfirm archlinux-keyring cachyos-keyring && \
2323
# Remove EXTERNALLY-MANAGED to allow pip usage if needed (optional but helpful)
2424
rm -f /usr/lib/python3.*/EXTERNALLY-MANAGED
2525

26-
# Force vcpkg to use system binaries
26+
# Install Vcpkg
27+
RUN git clone https://github.com/microsoft/vcpkg.git /opt/vcpkg && \
28+
/opt/vcpkg/bootstrap-vcpkg.sh && \
29+
# Clean up to reduce image size
30+
rm -rf /opt/vcpkg/downloads/* && \
31+
rm -rf /opt/vcpkg/buildtrees/* && \
32+
rm -rf /opt/vcpkg/packages/*
33+
34+
# Environment variables
35+
ENV VCPKG_ROOT=/opt/vcpkg
36+
ENV PATH=$VCPKG_ROOT:$PATH
2737
ENV VCPKG_FORCE_SYSTEM_BINARIES=1

0 commit comments

Comments
 (0)