|
1 | | -import { ensureDir } from "jsr:@std/fs@0.218/ensure_dir"; |
| 1 | +import { $ } from "jsr:@david/dax@0.42.0"; |
2 | 2 |
|
3 | | -const decoder = new TextDecoder(); |
4 | | -const architectures = [["x86_64", "x86_64"], ["aarch64", "arm64"]] as const; |
| 3 | +const { os } = Deno.build; |
| 4 | +$.setPrintCommand(true); |
5 | 5 |
|
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`; |
99 | 11 | 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`; |
127 | 19 | 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`; |
160 | 37 | break; |
161 | | - } |
162 | 38 | } |
0 commit comments