-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Update webview, add linux ARM target (#189)
- Loading branch information
Showing
5 changed files
with
82 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,29 @@ | ||
@echo off | ||
|
||
echo Prepare directories... | ||
set script_dir=%~dp0 | ||
set src_dir=%script_dir%..\webview | ||
set build_dir=%script_dir%..\build | ||
mkdir "%build_dir%" | ||
|
||
echo Webview directory: %src_dir% | ||
echo Build directory: %build_dir% | ||
|
||
:: If you update the nuget package, change its version here | ||
set nuget_version=1.0.1150.38 | ||
echo Using Nuget Package microsoft.web.webview2.%nuget_version% | ||
if not exist "%script_dir%\microsoft.web.webview2.%nuget_version%" ( | ||
curl -sSLO https://dist.nuget.org/win-x86-commandline/latest/nuget.exe | ||
nuget.exe install Microsoft.Web.Webview2 -Version %nuget_version% -OutputDirectory %script_dir% | ||
echo Nuget package installed | ||
) | ||
|
||
echo Looking for vswhere.exe... | ||
set "vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" | ||
if not exist "%vswhere%" set "vswhere=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" | ||
if not exist "%vswhere%" ( | ||
echo ERROR: Failed to find vswhere.exe | ||
exit /b 1 | ||
echo ERROR: Failed to find vswhere.exe | ||
exit /b 1 | ||
) | ||
echo Found %vswhere% | ||
|
||
echo Looking for VC... | ||
for /f "usebackq tokens=*" %%i in (`"%vswhere%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( | ||
set vc_dir=%%i | ||
set vc_dir=%%i | ||
) | ||
if not exist "%vc_dir%\Common7\Tools\vsdevcmd.bat" ( | ||
echo ERROR: Failed to find VC tools x86/x64 | ||
exit /b 1 | ||
echo ERROR: Failed to find VC tools x86/x64 | ||
exit /b 1 | ||
) | ||
echo Found %vc_dir% | ||
|
||
:: 4100: unreferenced formal parameter | ||
set warning_params=/W4 /wd4100 | ||
|
||
:: build dlls if not found | ||
if not exist "%src_dir%\dll\x64\webview.dll" ( | ||
mkdir "%src_dir%\dll\x86" | ||
mkdir "%src_dir%\dll\x64" | ||
copy "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x64\WebView2Loader.dll" "%src_dir%\dll\x64" | ||
copy "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x86\WebView2Loader.dll" "%src_dir%\dll\x86" | ||
|
||
call "%vc_dir%\Common7\Tools\vsdevcmd.bat" -arch=x86 -host_arch=x64 | ||
|
||
echo "Building webview.dll (x86)" | ||
cl %warning_params% ^ | ||
/D "WEBVIEW_API=__declspec(dllexport)" ^ | ||
/I "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\include" ^ | ||
"%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x86\WebView2Loader.dll.lib" ^ | ||
/std:c++17 /EHsc "/Fo%build_dir%"\ ^ | ||
"%src_dir%\webview.cc" /link /DLL "/OUT:%src_dir%\dll\x86\webview.dll" || exit \b | ||
call "%vc_dir%\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64 | ||
cd %~dp0..\webview | ||
|
||
call "%vc_dir%\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64 | ||
echo "Building webview.dll (x64)" | ||
cl %warning_params% ^ | ||
/D "WEBVIEW_API=__declspec(dllexport)" ^ | ||
/I "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\include" ^ | ||
"%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x64\WebView2Loader.dll.lib" ^ | ||
/std:c++17 /EHsc "/Fo%build_dir%"\ ^ | ||
"%src_dir%\webview.cc" /link /DLL "/OUT:%src_dir%\dll\x64\webview.dll" || exit \b | ||
) | ||
if not exist "%build_dir%\webview.dll" ( | ||
copy "%src_dir%\dll\x64\webview.dll" %build_dir% | ||
) | ||
if not exist "%build_dir%\WebView2Loader.dll" ( | ||
copy "%script_dir%\microsoft.web.webview2.%nuget_version%\build\native\x64\WebView2Loader.dll" "%build_dir%" | ||
) | ||
cmake -G "Ninja Multi-Config" -B build -S . ^ | ||
-DWEBVIEW_BUILD_DOCS=OFF ^ | ||
-DWEBVIEW_USE_CLANG_TIDY=OFF ^ | ||
-DWEBVIEW_USE_CLANG_FORMAT=OFF | ||
|
||
call "%vc_dir%\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64 | ||
cmake --build build --config Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,162 +1,38 @@ | ||
import { ensureDir } from "jsr:@std/fs@0.218/ensure_dir"; | ||
import { $ } from "jsr:@david/dax@0.42.0"; | ||
|
||
const decoder = new TextDecoder(); | ||
const architectures = [["x86_64", "x86_64"], ["aarch64", "arm64"]] as const; | ||
const { os } = Deno.build; | ||
$.setPrintCommand(true); | ||
|
||
const ExitType = { | ||
Exit: "exit", | ||
Fail: "fail", | ||
Never: "never", | ||
} as const; | ||
type ExitType = typeof ExitType[keyof typeof ExitType]; | ||
|
||
const LogType = { | ||
Success: "success", | ||
Always: "always", | ||
Fail: "fail", | ||
Never: "never", | ||
} as const; | ||
type LogType = typeof LogType[keyof typeof LogType]; | ||
|
||
function indent(source: string, spaces = 2): string { | ||
return source.split("\n").map((line) => `${" ".repeat(spaces)}${line}\n`) | ||
.join(""); | ||
} | ||
|
||
async function command<T extends Deno.CommandOptions>( | ||
cmd: string, | ||
{ opts, exit, log }: { opts?: T; exit?: ExitType; log?: LogType } = {}, | ||
): Promise<{ | ||
code: number; | ||
stdout: string; | ||
stderr: string; | ||
}> { | ||
if (opts !== undefined) { | ||
opts.stdout = "piped"; | ||
opts.stderr = "piped"; | ||
} | ||
|
||
exit ??= ExitType.Never; | ||
log ??= LogType.Always; | ||
|
||
const command = new Deno.Command(cmd, opts); | ||
const { code, stdout, stderr } = await command.output(); | ||
|
||
const stdoutStr = decoder.decode(stdout); | ||
const stderrStr = decoder.decode(stderr); | ||
|
||
if (code === 0) { | ||
if (log !== "never") { | ||
console.log(`Successfully ran "${cmd} ${(opts?.args ?? []).join(" ")}"`); | ||
} | ||
|
||
if (log === "success" || log === "always") { | ||
if (stdoutStr.length !== 0) { | ||
console.log(`stdout:\n${indent(stdoutStr)}`); | ||
} | ||
if (stderrStr.length !== 0) { | ||
console.log(`stderr:\n${indent(stderrStr)}`); | ||
} | ||
} | ||
} else { | ||
if (log !== "never") { | ||
console.log(`Failed run "${cmd}"`); | ||
} | ||
|
||
if (log === "fail" || log === "always") { | ||
if (stdoutStr.length !== 0) { | ||
console.log(`stdout:\n${indent(stdoutStr)}`); | ||
} | ||
if (stderrStr.length !== 0) { | ||
console.log(`stderr:\n${indent(stderrStr)}`); | ||
} | ||
console.log(`code: ${code}`); | ||
} | ||
|
||
if (exit === ExitType.Fail) { | ||
Deno.exit(code); | ||
} | ||
} | ||
|
||
if (exit === ExitType.Exit) { | ||
Deno.exit(code); | ||
} | ||
|
||
return { | ||
code, | ||
stdout: stdoutStr, | ||
stderr: stderrStr, | ||
}; | ||
} | ||
|
||
await ensureDir("build"); | ||
|
||
switch (Deno.build.os) { | ||
case "windows": { | ||
await command("script/build.bat", { | ||
exit: ExitType.Exit, | ||
}); | ||
await $.path("./build").ensureDir(); | ||
switch (os) { | ||
case "windows": | ||
await $`script/build.bat`; | ||
await $`cp webview/build/core/Release/webview.dll build/webview.dll`; | ||
break; | ||
} | ||
|
||
case "darwin": { | ||
for (const [denoArch, gccArch] of architectures) { | ||
await command("c++", { | ||
opts: { | ||
exit: ExitType.Fail, | ||
args: [ | ||
"webview/webview.cc", | ||
"-dynamiclib", | ||
"-fpic", | ||
"-DWEBVIEW_COCOA", | ||
"-std=c++11", | ||
"-Wall", | ||
"-Wextra", | ||
"-pedantic", | ||
"-framework", | ||
"WebKit", | ||
"-arch", | ||
gccArch, | ||
"-o", | ||
`build/libwebview.${denoArch}.dylib`, | ||
], | ||
}, | ||
}); | ||
} | ||
Deno.exit(0); | ||
case "linux": | ||
$.cd("webview"); | ||
await $`export PATH=/usr/lib/llvm14/bin/:/usr/lib/llvm-14/bin/:/usr/lib64/llvm15/bin/:$PATH`; | ||
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`; | ||
await $`cmake --build build`; | ||
await $`cp build/core/libwebview.so ../build/libwebview.${Deno.build.arch}.so`; | ||
await $`strip ../build/libwebview.${Deno.build.arch}.so`; | ||
break; | ||
} | ||
|
||
case "linux": { | ||
const { stdout } = await command("pkg-config", { | ||
opts: { | ||
args: [ | ||
"--cflags", | ||
"--libs", | ||
"gtk+-3.0", | ||
"webkit2gtk-4.0", | ||
], | ||
}, | ||
}); | ||
await command("c++", { | ||
opts: { | ||
exit: ExitType.Fail, | ||
args: [ | ||
"webview/webview.cc", | ||
"-DWEBVIEW_GTK", | ||
"-shared", | ||
"-std=c++11", | ||
"-Wall", | ||
"-Wextra", | ||
"-pedantic", | ||
"-fpic", | ||
...stdout.trim().split(" "), | ||
"-o", | ||
"build/libwebview.so", | ||
], | ||
}, | ||
}); | ||
Deno.exit(0); | ||
case "darwin": | ||
$.cd("webview"); | ||
await $`cmake -G "Ninja Multi-Config" -B build -S . \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DWEBVIEW_BUILD_TESTS=OFF \ | ||
-DWEBVIEW_BUILD_EXAMPLES=OFF \ | ||
-DWEBVIEW_USE_CLANG_TOOLS=OFF \ | ||
-DWEBVIEW_ENABLE_CHECKS=OFF \ | ||
-DWEBVIEW_USE_CLANG_TIDY=OFF \ | ||
-DWEBVIEW_BUILD_DOCS=OFF \ | ||
-DWEBVIEW_USE_CLANG_FORMAT=OFF \ | ||
-DWEBVIEW_CLANG_FORMAT_EXE=${Deno.env.get( | ||
"WEBVIEW_CLANG_FORMAT_EXE", | ||
)!}`; | ||
await $`cmake --build build --config Release`; | ||
await $`cp build/core/Release/libwebview.dylib ../build/libwebview.${Deno.build.arch}.dylib`; | ||
await $`strip -x -S ../build/libwebview.${Deno.build.arch}.dylib`; | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters