Skip to content

Commit 999191a

Browse files
authored
feat!: Update webview, add linux ARM target (#189)
1 parent 84671ea commit 999191a

File tree

5 files changed

+82
-231
lines changed

5 files changed

+82
-231
lines changed

.github/workflows/build.yml

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ jobs:
1919
timeout-minutes: 60
2020
strategy:
2121
matrix:
22-
os: [macos-latest, windows-latest, ubuntu-latest]
22+
os:
23+
[
24+
macos-latest,
25+
macos-13,
26+
windows-latest,
27+
ubuntu-latest,
28+
ubuntu-24.04-arm,
29+
]
2330

2431
steps:
2532
- name: Clone repository
@@ -33,10 +40,22 @@ jobs:
3340
deno-version: v2.x
3441

3542
- name: install webkit2gtk (Linux)
36-
if: matrix.os == 'ubuntu-latest'
43+
if: startsWith(matrix.os, 'ubuntu')
3744
run: |
3845
sudo apt-get update
39-
sudo apt-get install -y webkit2gtk-4.0
46+
sudo apt-get install -y webkitgtk-6.0 libwebkitgtk-6.0-dev cmake ninja-build clang pkg-config libgtk-4-dev
47+
48+
- name: Install ninja (macOS)
49+
if: startsWith(matrix.os, 'macos')
50+
run: |
51+
brew install ninja
52+
brew install llvm
53+
echo "WEBVIEW_CLANG_FORMAT_EXE=$(brew --prefix llvm)/bin/clang-format" >> $GITHUB_ENV
54+
55+
- name: Install ninja (Windows)
56+
if: matrix.os == 'windows-latest'
57+
run: |
58+
choco install ninja
4059
4160
- name: Build dynamic library
4261
run: deno task build
@@ -50,15 +69,17 @@ jobs:
5069
build/*.dylib
5170
build/*.so
5271
53-
# - name: Release Plugin
54-
# uses: softprops/action-gh-release@master
55-
# env:
56-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57-
# with:
58-
# tag_name: "webview_deno release"
59-
# draft: true
60-
# files: |
61-
# build/libwebview.x86_64.dylib
62-
# build/libwebview.so
63-
# build/webview.dll
64-
# build/Webview2Loader.dll
72+
# - name: Release Plugin
73+
# uses: softprops/action-gh-release@master
74+
# env:
75+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
# with:
77+
# tag_name: "webview_deno release"
78+
# draft: true
79+
# files: |
80+
# build/libwebview.x86_64.dylib
81+
# build/libwebview.aarch64.dylib
82+
# build/libwebview.x86_64.so
83+
# build/libwebview.aarch64.so
84+
# build/webview.dll
85+
# build/Webview2Loader.dll

script/build.bat

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,29 @@
11
@echo off
2-
3-
echo Prepare directories...
4-
set script_dir=%~dp0
5-
set src_dir=%script_dir%..\webview
6-
set build_dir=%script_dir%..\build
7-
mkdir "%build_dir%"
8-
9-
echo Webview directory: %src_dir%
10-
echo Build directory: %build_dir%
11-
12-
:: If you update the nuget package, change its version here
13-
set nuget_version=1.0.1150.38
14-
echo Using Nuget Package microsoft.web.webview2.%nuget_version%
15-
if not exist "%script_dir%\microsoft.web.webview2.%nuget_version%" (
16-
curl -sSLO https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
17-
nuget.exe install Microsoft.Web.Webview2 -Version %nuget_version% -OutputDirectory %script_dir%
18-
echo Nuget package installed
19-
)
20-
212
echo Looking for vswhere.exe...
223
set "vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
234
if not exist "%vswhere%" set "vswhere=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe"
245
if not exist "%vswhere%" (
25-
echo ERROR: Failed to find vswhere.exe
26-
exit /b 1
6+
echo ERROR: Failed to find vswhere.exe
7+
exit /b 1
278
)
289
echo Found %vswhere%
2910

3011
echo Looking for VC...
3112
for /f "usebackq tokens=*" %%i in (`"%vswhere%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
32-
set vc_dir=%%i
13+
set vc_dir=%%i
3314
)
3415
if not exist "%vc_dir%\Common7\Tools\vsdevcmd.bat" (
35-
echo ERROR: Failed to find VC tools x86/x64
36-
exit /b 1
16+
echo ERROR: Failed to find VC tools x86/x64
17+
exit /b 1
3718
)
3819
echo Found %vc_dir%
3920

40-
:: 4100: unreferenced formal parameter
41-
set warning_params=/W4 /wd4100
42-
43-
:: build dlls if not found
44-
if not exist "%src_dir%\dll\x64\webview.dll" (
45-
mkdir "%src_dir%\dll\x86"
46-
mkdir "%src_dir%\dll\x64"
47-
copy "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x64\WebView2Loader.dll" "%src_dir%\dll\x64"
48-
copy "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x86\WebView2Loader.dll" "%src_dir%\dll\x86"
49-
50-
call "%vc_dir%\Common7\Tools\vsdevcmd.bat" -arch=x86 -host_arch=x64
51-
52-
echo "Building webview.dll (x86)"
53-
cl %warning_params% ^
54-
/D "WEBVIEW_API=__declspec(dllexport)" ^
55-
/I "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\include" ^
56-
"%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x86\WebView2Loader.dll.lib" ^
57-
/std:c++17 /EHsc "/Fo%build_dir%"\ ^
58-
"%src_dir%\webview.cc" /link /DLL "/OUT:%src_dir%\dll\x86\webview.dll" || exit \b
21+
call "%vc_dir%\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64
22+
cd %~dp0..\webview
5923

60-
call "%vc_dir%\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64
61-
echo "Building webview.dll (x64)"
62-
cl %warning_params% ^
63-
/D "WEBVIEW_API=__declspec(dllexport)" ^
64-
/I "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\include" ^
65-
"%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x64\WebView2Loader.dll.lib" ^
66-
/std:c++17 /EHsc "/Fo%build_dir%"\ ^
67-
"%src_dir%\webview.cc" /link /DLL "/OUT:%src_dir%\dll\x64\webview.dll" || exit \b
68-
)
69-
if not exist "%build_dir%\webview.dll" (
70-
copy "%src_dir%\dll\x64\webview.dll" %build_dir%
71-
)
72-
if not exist "%build_dir%\WebView2Loader.dll" (
73-
copy "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x64\WebView2Loader.dll" "%build_dir%"
74-
)
24+
cmake -G "Ninja Multi-Config" -B build -S . ^
25+
-DWEBVIEW_BUILD_DOCS=OFF ^
26+
-DWEBVIEW_USE_CLANG_TIDY=OFF ^
27+
-DWEBVIEW_USE_CLANG_FORMAT=OFF
7528

76-
call "%vc_dir%\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64
29+
cmake --build build --config Release

script/build.ts

Lines changed: 32 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,38 @@
1-
import { ensureDir } from "jsr:@std/fs@0.218/ensure_dir";
1+
import { $ } from "jsr:@david/dax@0.42.0";
22

3-
const decoder = new TextDecoder();
4-
const architectures = [["x86_64", "x86_64"], ["aarch64", "arm64"]] as const;
3+
const { os } = Deno.build;
4+
$.setPrintCommand(true);
55

6-
const ExitType = {
7-
Exit: "exit",
8-
Fail: "fail",
9-
Never: "never",
10-
} as const;
11-
type ExitType = typeof ExitType[keyof typeof ExitType];
12-
13-
const LogType = {
14-
Success: "success",
15-
Always: "always",
16-
Fail: "fail",
17-
Never: "never",
18-
} as const;
19-
type LogType = typeof LogType[keyof typeof LogType];
20-
21-
function indent(source: string, spaces = 2): string {
22-
return source.split("\n").map((line) => `${" ".repeat(spaces)}${line}\n`)
23-
.join("");
24-
}
25-
26-
async function command<T extends Deno.CommandOptions>(
27-
cmd: string,
28-
{ opts, exit, log }: { opts?: T; exit?: ExitType; log?: LogType } = {},
29-
): Promise<{
30-
code: number;
31-
stdout: string;
32-
stderr: string;
33-
}> {
34-
if (opts !== undefined) {
35-
opts.stdout = "piped";
36-
opts.stderr = "piped";
37-
}
38-
39-
exit ??= ExitType.Never;
40-
log ??= LogType.Always;
41-
42-
const command = new Deno.Command(cmd, opts);
43-
const { code, stdout, stderr } = await command.output();
44-
45-
const stdoutStr = decoder.decode(stdout);
46-
const stderrStr = decoder.decode(stderr);
47-
48-
if (code === 0) {
49-
if (log !== "never") {
50-
console.log(`Successfully ran "${cmd} ${(opts?.args ?? []).join(" ")}"`);
51-
}
52-
53-
if (log === "success" || log === "always") {
54-
if (stdoutStr.length !== 0) {
55-
console.log(`stdout:\n${indent(stdoutStr)}`);
56-
}
57-
if (stderrStr.length !== 0) {
58-
console.log(`stderr:\n${indent(stderrStr)}`);
59-
}
60-
}
61-
} else {
62-
if (log !== "never") {
63-
console.log(`Failed run "${cmd}"`);
64-
}
65-
66-
if (log === "fail" || log === "always") {
67-
if (stdoutStr.length !== 0) {
68-
console.log(`stdout:\n${indent(stdoutStr)}`);
69-
}
70-
if (stderrStr.length !== 0) {
71-
console.log(`stderr:\n${indent(stderrStr)}`);
72-
}
73-
console.log(`code: ${code}`);
74-
}
75-
76-
if (exit === ExitType.Fail) {
77-
Deno.exit(code);
78-
}
79-
}
80-
81-
if (exit === ExitType.Exit) {
82-
Deno.exit(code);
83-
}
84-
85-
return {
86-
code,
87-
stdout: stdoutStr,
88-
stderr: stderrStr,
89-
};
90-
}
91-
92-
await ensureDir("build");
93-
94-
switch (Deno.build.os) {
95-
case "windows": {
96-
await command("script/build.bat", {
97-
exit: ExitType.Exit,
98-
});
6+
await $.path("./build").ensureDir();
7+
switch (os) {
8+
case "windows":
9+
await $`script/build.bat`;
10+
await $`cp webview/build/core/Release/webview.dll build/webview.dll`;
9911
break;
100-
}
101-
102-
case "darwin": {
103-
for (const [denoArch, gccArch] of architectures) {
104-
await command("c++", {
105-
opts: {
106-
exit: ExitType.Fail,
107-
args: [
108-
"webview/webview.cc",
109-
"-dynamiclib",
110-
"-fpic",
111-
"-DWEBVIEW_COCOA",
112-
"-std=c++11",
113-
"-Wall",
114-
"-Wextra",
115-
"-pedantic",
116-
"-framework",
117-
"WebKit",
118-
"-arch",
119-
gccArch,
120-
"-o",
121-
`build/libwebview.${denoArch}.dylib`,
122-
],
123-
},
124-
});
125-
}
126-
Deno.exit(0);
12+
case "linux":
13+
$.cd("webview");
14+
await $`export PATH=/usr/lib/llvm14/bin/:/usr/lib/llvm-14/bin/:/usr/lib64/llvm15/bin/:$PATH`;
15+
await $`cmake -G Ninja -B build -S . -D CMAKE_BUILD_TYPE=Release -D WEBVIEW_WEBKITGTK_API=6.0 -DWEBVIEW_ENABLE_CHECKS=false -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/host-llvm.cmake -DWEBVIEW_USE_CLANG_TIDY=OFF -DWEBVIEW_BUILD_DOCS=OFF -DWEBVIEW_USE_CLANG_FORMAT=OFF`;
16+
await $`cmake --build build`;
17+
await $`cp build/core/libwebview.so ../build/libwebview.${Deno.build.arch}.so`;
18+
await $`strip ../build/libwebview.${Deno.build.arch}.so`;
12719
break;
128-
}
129-
130-
case "linux": {
131-
const { stdout } = await command("pkg-config", {
132-
opts: {
133-
args: [
134-
"--cflags",
135-
"--libs",
136-
"gtk+-3.0",
137-
"webkit2gtk-4.0",
138-
],
139-
},
140-
});
141-
await command("c++", {
142-
opts: {
143-
exit: ExitType.Fail,
144-
args: [
145-
"webview/webview.cc",
146-
"-DWEBVIEW_GTK",
147-
"-shared",
148-
"-std=c++11",
149-
"-Wall",
150-
"-Wextra",
151-
"-pedantic",
152-
"-fpic",
153-
...stdout.trim().split(" "),
154-
"-o",
155-
"build/libwebview.so",
156-
],
157-
},
158-
});
159-
Deno.exit(0);
20+
case "darwin":
21+
$.cd("webview");
22+
await $`cmake -G "Ninja Multi-Config" -B build -S . \
23+
-DCMAKE_BUILD_TYPE=Release \
24+
-DWEBVIEW_BUILD_TESTS=OFF \
25+
-DWEBVIEW_BUILD_EXAMPLES=OFF \
26+
-DWEBVIEW_USE_CLANG_TOOLS=OFF \
27+
-DWEBVIEW_ENABLE_CHECKS=OFF \
28+
-DWEBVIEW_USE_CLANG_TIDY=OFF \
29+
-DWEBVIEW_BUILD_DOCS=OFF \
30+
-DWEBVIEW_USE_CLANG_FORMAT=OFF \
31+
-DWEBVIEW_CLANG_FORMAT_EXE=${Deno.env.get(
32+
"WEBVIEW_CLANG_FORMAT_EXE",
33+
)!}`;
34+
await $`cmake --build build --config Release`;
35+
await $`cp build/core/Release/libwebview.dylib ../build/libwebview.${Deno.build.arch}.dylib`;
36+
await $`strip -x -S ../build/libwebview.${Deno.build.arch}.dylib`;
16037
break;
161-
}
16238
}

src/ffi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export const lib = await dlopen(
105105
url,
106106
cache,
107107
suffixes: {
108+
linux: `.${Deno.build.arch}`,
108109
darwin: `.${Deno.build.arch}`,
109110
},
110111
},

webview

Submodule webview updated 116 files

0 commit comments

Comments
 (0)