Skip to content

Commit 638803d

Browse files
committed
rebased and conflicts resolved
2 parents 13433e2 + 4294d90 commit 638803d

21 files changed

+4460
-1032
lines changed

PyPI/Package/src/webui/bootstrap.bat

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ SET "MACOS_X64=https://github.com/webui-dev/webui/releases/download/nightly/webu
2424
SET "WINDOWS_MSVC_X64=https://github.com/webui-dev/webui/releases/download/nightly/webui-windows-msvc-x64.zip"
2525

2626
:: Release
27-
:: SET "LINUX_ARM=https://github.com/webui-dev/webui/releases/download/2.4.2/webui-linux-gcc-arm.zip"
28-
:: SET "LINUX_ARM64=https://github.com/webui-dev/webui/releases/download/2.4.2/webui-linux-gcc-arm64.zip"
29-
:: SET "LINUX_X64=https://github.com/webui-dev/webui/releases/download/2.4.2/webui-linux-gcc-x64.zip"
30-
:: SET "MACOS_ARM64=https://github.com/webui-dev/webui/releases/download/2.4.2/webui-macos-clang-arm64.zip"
31-
:: SET "MACOS_X64=https://github.com/webui-dev/webui/releases/download/2.4.2/webui-macos-clang-x64.zip"
32-
:: SET "WINDOWS_MSVC_X64=https://github.com/webui-dev/webui/releases/download/2.4.2/webui-windows-msvc-x64.zip"
27+
:: SET "LINUX_ARM=https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-linux-gcc-arm.zip"
28+
:: SET "LINUX_ARM64=https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-linux-gcc-arm64.zip"
29+
:: SET "LINUX_X64=https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-linux-gcc-x64.zip"
30+
:: SET "MACOS_ARM64=https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-macos-clang-arm64.zip"
31+
:: SET "MACOS_X64=https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-macos-clang-x64.zip"
32+
:: SET "WINDOWS_MSVC_X64=https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-windows-msvc-x64.zip"
3333

3434
:: Download and extract archives
3535
CALL :DOWNLOAD_AND_EXTRACT %LINUX_ARM% webui-linux-gcc-arm webui-2.so
@@ -73,7 +73,11 @@ GOTO :EOF
7373
:: Download WebUI library for only the current OS.
7474
:MINIMAL
7575

76-
SET "BASE_URL=https://github.com/webui-dev/webui/releases/download/2.4.2/"
76+
:: Nightly base url
77+
SET "BASE_URL=https://github.com/webui-dev/webui/releases/download/nightly/"
78+
79+
:: Targeted base url
80+
:: SET "BASE_URL=https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/"
7781

7882
:: Check the CPU architecture
7983
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (

PyPI/Package/src/webui/bootstrap.sh

100644100755
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ if [[ "$1" == "" ]]; then
1515
# Nightly Build
1616
LINUX_ARM="https://github.com/webui-dev/webui/releases/download/nightly/webui-linux-gcc-arm.zip"
1717
LINUX_ARM64="https://github.com/webui-dev/webui/releases/download/nightly/webui-linux-gcc-arm64.zip"
18-
LINUX_X64="https://github.com/webui-dev/webui/releases/download/nightly/webui-linux-gcc-x64.zip"
18+
LINUX_GCC_X64="https://github.com/webui-dev/webui/releases/download/nightly/webui-linux-gcc-x64.zip"
19+
LINUX_CLANG_X64="https://github.com/webui-dev/webui/releases/download/nightly/webui-linux-clang-x64.zip"
1920
MACOS_ARM64="https://github.com/webui-dev/webui/releases/download/nightly/webui-macos-clang-arm64.zip"
2021
MACOS_X64="https://github.com/webui-dev/webui/releases/download/nightly/webui-macos-clang-x64.zip"
2122
WINDOWS_MSVC_X64="https://github.com/webui-dev/webui/releases/download/nightly/webui-windows-msvc-x64.zip"
2223

2324
# Release
24-
# LINUX_ARM="https://github.com/webui-dev/webui/releases/download/2.4.2/webui-linux-gcc-arm.zip"
25-
# LINUX_ARM64="https://github.com/webui-dev/webui/releases/download/2.4.2/webui-linux-gcc-arm64.zip"
26-
# LINUX_X64="https://github.com/webui-dev/webui/releases/download/2.4.2/webui-linux-gcc-x64.zip"
27-
# MACOS_ARM64="https://github.com/webui-dev/webui/releases/download/2.4.2/webui-macos-clang-arm64.zip"
28-
# MACOS_X64="https://github.com/webui-dev/webui/releases/download/2.4.2/webui-macos-clang-x64.zip"
29-
# WINDOWS_MSVC_X64="https://github.com/webui-dev/webui/releases/download/2.4.2/webui-windows-msvc-x64.zip"
25+
# LINUX_ARM="https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-linux-gcc-arm.zip"
26+
# LINUX_ARM64="https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-linux-gcc-arm64.zip"
27+
# LINUX_GCC_X64="https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-linux-gcc-x64.zip"
28+
# LINUX_CLANG_X64="https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-linux-clang-x64.zip"
29+
# MACOS_ARM64="https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-macos-clang-arm64.zip"
30+
# MACOS_X64="https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-macos-clang-x64.zip"
31+
# WINDOWS_MSVC_X64="https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/webui-windows-msvc-x64.zip"
3032

3133
# Download and extract archives
3234
download_and_extract() {
@@ -49,7 +51,8 @@ if [[ "$1" == "" ]]; then
4951

5052
download_and_extract $LINUX_ARM "webui-linux-gcc-arm" "webui-2.so"
5153
download_and_extract $LINUX_ARM64 "webui-linux-gcc-arm64" "webui-2.so"
52-
download_and_extract $LINUX_X64 "webui-linux-gcc-x64" "webui-2.so"
54+
download_and_extract $LINUX_GCC_X64 "webui-linux-gcc-x64" "webui-2.so"
55+
download_and_extract $LINUX_CLANG_X64 "webui-linux-clang-x64" "webui-2.so"
5356
download_and_extract $MACOS_ARM64 "webui-macos-clang-arm64" "webui-2.dylib"
5457
download_and_extract $MACOS_X64 "webui-macos-clang-x64" "webui-2.dylib"
5558
download_and_extract $WINDOWS_MSVC_X64 "webui-windows-msvc-x64" "webui-2.dll"
@@ -66,14 +69,14 @@ if [[ "$1" == "minimal" ]]; then
6669
# Download WebUI library for only the current OS.
6770

6871
# Nightly Build
69-
# BASE_URL="https://github.com/webui-dev/webui/releases/download/nightly/"
72+
BASE_URL="https://github.com/webui-dev/webui/releases/download/nightly/"
7073

7174
# Release
72-
BASE_URL="https://github.com/webui-dev/webui/releases/download/2.4.2/"
75+
# BASE_URL="https://github.com/webui-dev/webui/releases/download/2.5.0-beta.2/"
7376

7477
# Detect OS (macOS / Linux)
7578
OS="linux"
76-
CC="gcc"
79+
CC="clang" # "gcc"
7780
EXT="so"
7881
if [[ "$OSTYPE" == "darwin"* ]]; then
7982
OS="macos"
@@ -97,6 +100,9 @@ if [[ "$1" == "minimal" ]]; then
97100
elif [ "$ARCH" = "aarch64" ]; then
98101
# ARM 64Bit
99102
FILENAME="webui-${OS}-${CC}-arm64"
103+
elif [ "$ARCH" = "arm64" ]; then
104+
# ARM 64bit - apple
105+
FILENAME="webui-${OS}-${CC}-arm64"
100106
else
101107
echo "Error: Unknown architecture '$ARCH'"
102108
exit 1
@@ -106,7 +112,11 @@ if [[ "$1" == "minimal" ]]; then
106112
mkdir -p "cache/$FILENAME" 2>/dev/null
107113

108114
# Download the archive using wget
109-
wget -q "$BASE_URL$FILENAME.zip" -O "cache/$FILENAME.zip"
115+
if [ "$ARCH" = "arm64" ]; then
116+
curl -sL "$BASE_URL$FILENAME.zip" -o "cache/$FILENAME.zip"
117+
else
118+
wget -q "$BASE_URL$FILENAME.zip" -O "cache/$FILENAME.zip"
119+
fi
110120

111121
# Extract archive
112122
unzip -q "cache/$FILENAME.zip" -d "cache"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from __future__ import annotations
2+
3+
import subprocess
4+
import os
5+
import platform
6+
import sys
7+
from ctypes import *
8+
9+
10+
def _get_current_folder() -> str:
11+
return os.path.dirname(os.path.abspath(__file__))
12+
13+
14+
def _get_architecture() -> str:
15+
arch = platform.machine()
16+
if arch in ['x86_64', 'AMD64', 'amd64']:
17+
return 'x64'
18+
elif arch in ['aarch64', 'ARM64', 'arm64']:
19+
return 'arm64'
20+
elif arch in ['arm']:
21+
return 'arm'
22+
else:
23+
return arch
24+
25+
26+
def _get_library_folder_name() -> str:
27+
arch = _get_architecture()
28+
if platform.system() == 'Darwin':
29+
return f'/webui-macos-clang-{arch}/webui-2.dylib'
30+
elif platform.system() == 'Windows':
31+
return f'\\webui-windows-msvc-{arch}\\webui-2.dll'
32+
elif platform.system() == 'Linux':
33+
return f'/webui-linux-clang-{arch}/webui-2.so' # return f'/webui-linux-gcc-{arch}/webui-2.so'
34+
else:
35+
return ""
36+
37+
38+
def _get_library_path() -> str:
39+
folderName = _get_library_folder_name()
40+
return _get_current_folder() + folderName
41+
42+
43+
def run_cmd(command):
44+
subprocess.run(command, shell=True)
45+
46+
47+
def _download_library():
48+
script = 'bash bootstrap.sh'
49+
cd = 'cd '
50+
if platform.system() == 'Windows':
51+
script = 'bootstrap.bat'
52+
cd = 'cd /d '
53+
# Run: `cd {folder} && bootstrap.sh minimal`
54+
run_cmd(cd + _get_current_folder() +
55+
' && ' + script + ' minimal')
56+
57+
58+
# Load WebUI Dynamic Library
59+
def _load_library() -> CDLL:
60+
library: CDLL | None = None
61+
lib_path = _get_library_path()
62+
if not os.path.exists(lib_path):
63+
_download_library()
64+
65+
if not os.path.exists(lib_path):
66+
return library
67+
68+
if platform.system() == 'Darwin':
69+
library = CDLL(lib_path)
70+
if library is None:
71+
print("WebUI Dynamic Library not found.")
72+
elif platform.system() == 'Windows':
73+
if sys.version_info.major==3 and sys.version_info.minor<=8:
74+
os.chdir(os.getcwd())
75+
os.add_dll_directory(os.getcwd())
76+
library = CDLL(lib_path)
77+
else:
78+
os.chdir(os.getcwd())
79+
os.add_dll_directory(os.getcwd())
80+
library = cdll.LoadLibrary(lib_path)
81+
if library is None:
82+
print("WebUI Dynamic Library not found.")
83+
elif platform.system() == 'Linux':
84+
library = CDLL(lib_path)
85+
if library is None:
86+
print("WebUI Dynamic Library not found.")
87+
else:
88+
print("Unsupported OS")
89+
90+
return library

0 commit comments

Comments
 (0)