1 ! Copyright (C) 2023 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors ascii assocs build-from-source cli.git
4 combinators.short-circuit combinators.smart continuations
5 environment github html.parser html.parser.analyzer http.client
6 io.directories io.encodings.string io.encodings.utf8
7 io.files.temp io.launcher io.pathnames json kernel layouts math
8 namespaces qw sequences sorting.human splitting windows.shell32 ;
9 IN: build-from-source.windows
11 ! choco install -y meson StrawberryPerl nasm winflexbison3 glfw3 jom
12 ! jom is for building openssl in parallel
14 ! From `choco install -y nasm`
15 ! Add nasm to path (windows+r sysdm.cpl -> Advanced tab -> Environment Variables -> New -> "c:\Program Files\NASM")
16 : check-nasm ( -- ) { "nasm.exe" "-h" } try-process ;
17 : have-jom? ( -- ? ) [ { "jom" } try-process t ] [ drop f ] recover ;
19 ! From `choco install -y StrawberryPerl`
20 ! make sure it is above the git /usr/bin/perl (if that is installed)
21 ! TODO: https://stackoverflow.com/questions/5898131/set-a-persistent-environment-variable-from-cmd-exe
22 : check-perl ( -- ) { "perl" "-h" } try-process ;
24 ! From vcvarsall.bat (x64 Native Tools Command Prompt runs this automatically)
25 : check-nmake ( -- ) { "nmake" "/?" } try-process ;
26 : check-cmake ( -- ) { "cmake" "-h" } try-process ;
27 : check-msbuild ( -- ) { "msbuild" "-h" } try-process ;
29 : build-fftw-dll ( -- )
33 { "cmake" "-G" "Visual Studio 17 2022" "-A" "Win32" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
34 qw{ msbuild fftw.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
36 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
37 qw{ msbuild fftw.sln /m /property:Configuration=Release } try-process
39 "Release/fftw3.dll" copy-output-file
40 ] with-build-directory
43 : build-winflexbison ( -- )
44 "lexxmark" "winflexbison" winflexbison-versions last [
46 qw{ cmake .. } try-process
47 qw{ cmake --build . --config Release --target package } try-process
48 ] with-build-directory
49 "bin/Release/win_bison.exe" "bison.exe" copy-vm-file-as
50 "bin/Release/win_flex.exe" "flex.exe" copy-vm-file-as
51 ] with-github-worktree-tag ;
54 "xianyi" "OpenBLAS" blas-versions last [
57 { "cmake" "-G" "Visual Studio 17 2022" "-A" "Win32" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
58 qw{ msbuild OpenBLAS.sln /property:Configuration=Release /p:Platform=Win32 } try-process
60 { "cmake" "-G" "Visual Studio 17 2022" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
61 qw{ msbuild OpenBLAS.sln /property:Configuration=Release } try-process
63 "lib/RELEASE/openblas.dll" "blas.dll" copy-output-file-as
64 ] with-build-directory
65 ] with-github-worktree-tag ;
67 : build-openssl-32-dlls ( -- )
68 "openssl" "openssl" openssl-versions last [
70 "ProgramW6432" os-env program-files or
71 "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
74 qw{ perl Configure -DOPENSSL_PIC VC-WIN32 /FS } try-process
75 have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
76 { "libssl-3.dll" "libcrypto-3.dll" } copy-output-files
77 ] with-github-worktree-tag ;
79 : build-openssl-64-dlls ( -- )
80 "openssl" "openssl" openssl-versions last [
82 program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
85 qw{ perl Configure -DOPENSSL_PIC VC-WIN64A /FS } try-process
86 have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
87 { "apps/libssl-3-x64.dll" "apps/libcrypto-3-x64.dll" } copy-output-files
88 ] with-github-worktree-tag ;
90 : build-openssl-dlls ( -- )
91 32-bit? [ build-openssl-32-dlls ] [ build-openssl-64-dlls ] if ;
93 : build-cairo-dll ( -- )
94 "gitlab.freedesktop.org" "cairo" "cairo" cairo-versions first [
95 qw{ meson setup --force-fallback-for=freetype2,fontconfig,zlib,expat,expat_dep build } try-process
96 "build" prepend-current-path
97 [ { "ninja" } try-process ] with-directory
98 "." find-dlls copy-output-files
100 "gdbus-example-objectmanager.dll"
101 "moduletestplugin_a_library.dll"
102 "moduletestplugin_a_plugin.dll"
103 "moduletestplugin_b_library.dll"
104 "moduletestplugin_b_plugin.dll"
107 } delete-output-files
108 ] with-gitlab-worktree-tag ;
110 : build-libressl-dlls ( -- )
114 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
115 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
117 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
118 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
120 "crypto/Release/crypto.dll" "libressl-crypto.dll" copy-output-file-as
121 "ssl/Release/ssl.dll" "libressl-ssl.dll" copy-output-file-as
122 "tls/Release/tls.dll" "libressl-tls.dll" copy-output-file-as
123 ] with-build-directory
126 : build-openal-dll ( -- )
127 "kcat" "openal-soft" openal-versions last [
132 "-G" "Visual Studio 17 2022"
134 "-DCMAKE_BUILD_TYPE=Release"
135 "-DBUILD_SHARED_LIBS=ON" ".."
137 qw{ msbuild OpenAL.sln /property:Configuration=Release /p:Platform=Win32 } try-process
141 "-G" "Visual Studio 17 2022"
142 "-DCMAKE_BUILD_TYPE=Release"
143 "-DBUILD_SHARED_LIBS=ON" ".."
145 qw{ msbuild OpenAL.sln /property:Configuration=Release } try-process
147 "Release/OpenAL32.dll" copy-output-file
148 ] with-build-directory
149 ] with-github-worktree-tag ;
151 : build-grpc-dll ( -- )
152 "grpc" "grpc" grpc-versions last [
153 qw{ git submodule init } try-process
154 qw{ git submodule update } try-process
155 qw{ rm -rf third_party\boringssl-with-bazel } try-process
156 ! grpc has a file called BUILD so use build2
161 "-G" "Visual Studio 17 2022"
163 "-DCMAKE_BUILD_TYPE=Release"
164 "-DBUILD_SHARED_LIBS=ON" ".."
166 qw{ msbuild grpc.sln /property:Configuration=Release /p:Platform=Win32 } try-process
170 "-G" "Visual Studio 17 2022"
171 "-DCMAKE_BUILD_TYPE=Release"
172 "-DBUILD_SHARED_LIBS=ON" ".."
174 qw{ msbuild grpc.sln /property:Configuration=Release } try-process
176 "bin/Release/libprotobuf-lite.dll" copy-output-file
177 "bin/Release/libprotobuf.dll" copy-output-file
178 "bin/Release/libprotoc.dll" copy-output-file
179 "bin/Release/abseil_dll.dll" copy-output-file
180 "bin/Release/protoc.exe" copy-output-file
181 ] with-build-directory-as
182 ] with-github-worktree-tag ;
184 : build-pcre-dll ( -- )
188 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON -DPCRE_SUPPORT_LIBZ=OFF -DPCRE_SUPPORT_LIBBZ2=OFF -DPCRE_SUPPORT_LIBREADLINE=OFF .. } try-process
189 qw{ msbuild PCRE.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
191 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
192 qw{ msbuild PCRE.sln /m /property:Configuration=Release } try-process
194 "Release/pcre.dll" copy-output-file
195 ] with-build-directory
198 : build-pcre2-dll ( -- )
199 "PCRE2Project" "pcre2" pcre2-versions last [
202 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE2_SUPPORT_UNICODE=ON -DPCRE2_SUPPORT_LIBZ=OFF -DPCRE2_SUPPORT_LIBBZ2=OFF -DPCRE2_SUPPORT_LIBEDIT=OFF -DPCRE2_SUPPORT_LIBREADLINE=OFF .. } try-process
203 qw{ msbuild PCRE2.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
205 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
206 qw{ msbuild PCRE2.sln /m /property:Configuration=Release } try-process
208 { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
209 ] with-build-directory
210 ] with-github-worktree-tag ;
212 ! choco install -y meson winflexbison3
213 : build-postgres-dll ( -- )
214 "postgres" "postgres" postgres-versions last [
215 "src/tools/msvc/clean.bat" prepend-current-path try-process
216 qw{ meson setup build } try-process
217 "build" prepend-current-path
218 [ { "ninja" } try-process ] with-directory
219 "build/src/interfaces/libpq/libpq.dll" copy-output-file
220 ] with-github-worktree-tag ;
222 ! choco install -y glfw3
223 : build-raylib-dll ( -- )
224 "raysan5" "raylib" raylib-versions last [
227 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
228 qw{ msbuild raylib.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
230 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
231 qw{ msbuild raylib.sln /m /property:Configuration=Release } try-process
233 "raylib/Release/raylib.dll" copy-output-file
234 ] with-build-directory
235 ] with-github-worktree-tag ;
237 :: build-raygui-dll ( -- )
238 "raysan5" "raygui" raygui-versions last [
239 "raysan5" "raylib" raylib-versions last github-tag-disk-checkout-path :> $raylib-dir
240 $raylib-dir "src" append-path :> $raylib-src
241 $raylib-dir "build/raylib/Release/raylib.lib" append-path :> $raylib-lib
243 "src/raygui.h" "src/raygui.c" copy-file
245 [ "cl" "/O2" "/I" $raylib-src "/D_USRDLL" "/D_WINDLL" "/DRAYGUI_IMPLEMENTATION" "/DBUILD_LIBTYPE_SHARED" "src/raygui.c" "/LD" "/Feraygui.dll" "/link" "/LIBPATH" $raylib-lib "/subsystem:windows" "/machine:x86" ] output>array try-process
247 [ "cl" "/O2" "/I" $raylib-src "/D_USRDLL" "/D_WINDLL" "/DRAYGUI_IMPLEMENTATION" "/DBUILD_LIBTYPE_SHARED" "src/raygui.c" "/LD" "/Feraygui.dll" "/link" "/LIBPATH" $raylib-lib "/subsystem:windows" "/machine:x64" ] output>array try-process
249 "raygui.dll" copy-output-file
250 ] with-github-worktree-tag ;
252 : build-ripgrep ( -- )
253 "BurntSushi" "ripgrep" ripgrep-versions last [
254 qw{ cargo build --release } try-process
255 "target/release/rg.exe" copy-output-file
256 ] with-github-worktree-tag ;
258 : build-snappy-dll ( -- )
259 "google" "snappy" snappy-versions last [
262 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
263 qw{ msbuild Snappy.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
265 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
266 qw{ msbuild Snappy.sln /m /property:Configuration=Release } try-process
268 "Release/snappy.dll" copy-output-file
269 ] with-build-directory
270 ] with-github-worktree-tag ;
272 : build-sqlite-dll ( -- )
273 "sqlite" "sqlite" sqlite-versions last [
274 qw{ nmake /f Makefile.msc clean } try-process
275 qw{ nmake /f Makefile.msc } try-process
276 "sqlite3.dll" copy-output-file
277 ] with-github-worktree-tag ;
279 : build-duckdb-dll ( -- )
280 "duckdb" "duckdb" duckdb-versions last [
283 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
284 qw{ msbuild duckdb.sln /property:Configuration=Release /p:Platform=Win32 } try-process
286 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
287 qw{ msbuild duckdb.sln /property:Configuration=Release } try-process
289 "src/Release/duckdb.dll" copy-output-file
290 "Release/duckdb.exe" copy-output-file
291 ] with-build-directory
292 ] with-github-worktree-tag ;
294 : build-yaml-dll ( -- )
295 "yaml" "libyaml" yaml-versions last [
298 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
299 qw{ msbuild yaml.sln /property:Configuration=Release /p:Platform=Win32 } try-process
301 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
302 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
305 "Release/yaml.dll" copy-output-file
306 ] with-build-directory
307 ] with-github-worktree-tag ;
309 : build-zeromq-dll ( -- )
310 "zeromq" "libzmq" zeromq-versions last [
313 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
314 qw{ msbuild ZeroMQ.sln /property:Configuration=Release /p:Platform=Win32 } try-process
316 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
317 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
319 "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
320 ] with-build-directory
321 ] with-github-worktree-tag ;
323 : build-zlib-dll ( -- )
324 "madler" "zlib" zlib-versions last [
325 qw{ nmake /f win32/Makefile.msc clean } try-process
326 qw{ nmake /f win32/Makefile.msc } try-process
327 "zlib1.dll" copy-output-file
328 ] with-github-worktree-tag ;
331 "lz4" "lz4" lz4-versions last [
335 qw{ cmake -A Win32 -DBUILD_SHARED_LIBS=ON .. } try-process
336 qw{ msbuild LZ4.sln /property:Configuration=Release /p:Platform=Win32 } try-process
338 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
339 qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
341 "Release/lz4.dll" copy-output-file
342 ] with-build-directory
344 ] with-github-worktree-tag ;
346 : build-zstd-dll ( -- )
347 "facebook" "zstd" zstd-versions last [
351 --buildtype=debugoptimized
353 -Dauto_features=enabled
357 -Ddefault_library=both
366 --buildtype=debugoptimized
368 -Dauto_features=enabled
372 -Ddefault_library=both
377 "builddir" prepend-current-path
379 { "ninja" } try-process
380 "lib/zstd-1.dll" copy-output-file
382 ] with-github-worktree-tag ;
384 ! Probably not needed on Windows 10+
385 : install-windows-redistributable ( -- )
387 "https://aka.ms/vs/17/release/vc_redist.x64.exe" download
388 qw{ vc_redist.x64.exe /install /passive /norestart } try-process
389 ] with-temp-directory ;
391 : build-windows-dlls ( -- )
392 dll-out-directory make-directories
399 32-bit? [ build-postgres-dll ] unless
413 ! build-ripgrep build-duckdb