Skip to content

Commit 026d07b

Browse files
committed
save point
1 parent 3a1f5a9 commit 026d07b

2 files changed

Lines changed: 12 additions & 206 deletions

File tree

.github/vcpkg/setup.py

Lines changed: 4 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -1,206 +1,12 @@
11
#!/usr/bin/env python3
2-
"""
3-
vcpkg Bootstrap Script
4-
5-
This script bootstraps vcpkg and sets up the environment for building WebFrame.
6-
It supports cross-platform builds with configurable OS and triplet targets.
7-
8-
Usage:
9-
python setup.py --os <windows|linux|macos> --triplet <x64-linux|x64-windows|etc>
10-
"""
112

123
import argparse
13-
import os
14-
import platform
154
import subprocess
165
import sys
17-
from pathlib import Path
18-
19-
20-
def get_vcpkg_root() -> Path:
21-
"""Get the vcpkg root directory."""
22-
script_dir = Path(__file__).parent.resolve()
23-
project_root = script_dir.parent.parent
24-
vcpkg_root = project_root / "vcpkg"
25-
return vcpkg_root
26-
27-
28-
def get_default_os() -> str:
29-
"""Get the default OS based on the current platform."""
30-
system = platform.system()
31-
if system == "Windows":
32-
return "windows"
33-
elif system == "Darwin":
34-
return "macos"
35-
else:
36-
return "linux"
37-
38-
39-
def get_default_triplet() -> str:
40-
"""Get the default triplet based on the current platform and architecture."""
41-
machine = platform.machine()
42-
system = platform.system()
43-
44-
# Map machine architectures
45-
arch = "x64" if machine in ("x86_64", "AMD64") else "x86"
46-
if machine in ("arm64", "aarch64"):
47-
arch = "arm64"
48-
49-
# Map OS to triplet
50-
if system == "Windows":
51-
return f"{arch}-windows"
52-
elif system == "Darwin":
53-
return f"{arch}-osx"
54-
else:
55-
return f"{arch}-linux"
56-
57-
58-
def bootstrap_vcpkg(vcpkg_root: Path) -> bool:
59-
"""
60-
Bootstrap vcpkg if it hasn't been already.
61-
62-
Args:
63-
vcpkg_root: Path to vcpkg directory
64-
65-
Returns:
66-
True if bootstrap was successful or already bootstrapped, False otherwise
67-
"""
68-
vcpkg_executable = vcpkg_root / ("vcpkg.exe" if sys.platform == "win32" else "vcpkg")
69-
70-
if vcpkg_executable.exists():
71-
print(f"✓ vcpkg already bootstrapped at {vcpkg_root}")
72-
return True
73-
74-
print(f"Bootstrapping vcpkg...")
75-
76-
# Clone vcpkg if not present
77-
if not vcpkg_root.exists():
78-
print(f"Cloning vcpkg to {vcpkg_root}")
79-
try:
80-
subprocess.run(
81-
["git", "clone", "https://github.com/Microsoft/vcpkg.git", str(vcpkg_root)],
82-
check=True,
83-
capture_output=True
84-
)
85-
except subprocess.CalledProcessError as e:
86-
print(f"Failed to clone vcpkg: {e.stderr.decode()}")
87-
return False
88-
89-
# Run bootstrap script
90-
try:
91-
if sys.platform == "win32":
92-
bootstrap_script = vcpkg_root / "bootstrap-vcpkg.bat"
93-
subprocess.run(
94-
[str(bootstrap_script)],
95-
cwd=vcpkg_root,
96-
check=True
97-
)
98-
else:
99-
bootstrap_script = vcpkg_root / "bootstrap-vcpkg.sh"
100-
subprocess.run(
101-
["bash", str(bootstrap_script)],
102-
cwd=vcpkg_root,
103-
check=True
104-
)
105-
print("vcpkg bootstrapped successfully")
106-
return True
107-
except subprocess.CalledProcessError as e:
108-
print(f"Bootstrap failed: {e}")
109-
return False
110-
1116

112-
def install_dependencies(vcpkg_root: Path, triplet: str, os_name: str) -> bool:
113-
"""
114-
Install project dependencies using vcpkg.
115-
116-
Args:
117-
vcpkg_root: Path to vcpkg directory
118-
triplet: Target triplet (e.g., x64-linux)
119-
os_name: Target OS (e.g., linux)
120-
121-
Returns:
122-
True if installation was successful, False otherwise
123-
"""
124-
vcpkg_executable = vcpkg_root / ("vcpkg.exe" if sys.platform == "win32" else "vcpkg")
125-
project_root = vcpkg_root.parent.parent
126-
127-
print(f"Installing dependencies for {triplet}...")
128-
129-
try:
130-
subprocess.run(
131-
[
132-
str(vcpkg_executable),
133-
"install",
134-
f"--triplet={triplet}",
135-
f"--manifest-root={project_root}",
136-
"--clean-after-build"
137-
],
138-
check=True
139-
)
140-
print(f"Dependencies installed successfully")
141-
return True
142-
except subprocess.CalledProcessError as e:
143-
print(f"Dependency installation failed: {e}")
144-
return False
145-
146-
147-
def main():
148-
parser = argparse.ArgumentParser(
149-
description="Bootstrap vcpkg and install WebFrame dependencies",
150-
formatter_class=argparse.RawDescriptionHelpFormatter,
151-
epilog="""
152-
Examples:
153-
python setup.py # Use system defaults
154-
python setup.py --os linux-latest --triplet x64-linux
155-
python setup.py --os windows-latest --triplet x64-windows
156-
python setup.py --triplet arm64-linux
157-
"""
158-
)
159-
160-
parser.add_argument(
161-
"--os",
162-
dest="os_name",
163-
choices=["windows-latest", "linux-latest", "macos-latest"],
164-
default=get_default_os(),
165-
help="Target operating system (default: %(default)s)"
166-
)
167-
168-
parser.add_argument(
169-
"--triplet",
170-
dest="triplet",
171-
default=get_default_triplet(),
172-
help="vcpkg triplet (default: %(default)s)"
173-
)
174-
175-
parser.add_argument(
176-
"--skip-bootstrap",
177-
action="store_true",
178-
help="Skip vcpkg bootstrap (assume already bootstrapped)"
179-
)
180-
7+
if __name__ == "__main__":
8+
parser = argparse.ArgumentParser(description="Setup vcpkg for the project")
9+
parser.add_argument("--vcpkg-root", type=str, default="vcpkg", help="Path to the vcpkg directory")
18110
args = parser.parse_args()
182-
183-
print(f"WebFrame vcpkg Setup")
184-
print(f" OS: {args.os_name}")
185-
print(f" Triplet: {args.triplet}")
186-
print()
187-
188-
vcpkg_root = get_vcpkg_root()
189-
190-
# Bootstrap vcpkg
191-
if not args.skip_bootstrap:
192-
if not bootstrap_vcpkg(vcpkg_root):
193-
sys.exit(1)
194-
195-
# Install dependencies
196-
if not install_dependencies(vcpkg_root, args.triplet, args.os_name):
197-
sys.exit(1)
198-
199-
print()
200-
print("Setup complete!")
201-
print(f" vcpkg root: {vcpkg_root}")
202-
print(f" Use CMAKE_TOOLCHAIN_FILE={vcpkg_root}/scripts/buildsystems/vcpkg.cmake")
203-
20411

205-
if __name__ == "__main__":
206-
main()
12+

.github/workflows/test.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ name: Test
22

33
on:
44
push:
5-
pull_request:
6-
7-
env:
8-
VCPKG_BINARY_SOURCES: "clear;files,${{ github.workspace }}/vcpkg-cache,readwrite"
95

106
jobs:
117
build:
128
name: Build (${{ matrix.os }})
139
runs-on: ${{ matrix.os }}
1410
strategy:
1511
fail-fast: false
12+
env:
13+
VCPKG_BINARY_SOURCES: >-
14+
clear;files,${{ github.workspace }}${{ matrix.os == 'windows-latest' && '\vcpkg-cache' || '/vcpkg-cache' }},readwrite
1615
matrix:
1716
include:
1817
- os: windows-latest
@@ -32,8 +31,9 @@ jobs:
3231
uses: ./.github/cache
3332
with:
3433
triplet: ${{ matrix.triplet }}
34+
- name: Clone vcpkg
35+
run: git clone https://github.com/microsoft/vcpkg
36+
37+
- name: Bootstrap vcpkg
38+
run: ${{matrix.os == 'windows-latest' && 'vcpkg\bootstrap-vcpkg.bat' || './vcpkg/bootstrap-vcpkg.sh'}}
3539

36-
- name: Setup vcpkg
37-
uses: lukka/run-vcpkg@v11
38-
with:
39-
runVcpkgInstall: true

0 commit comments

Comments
 (0)