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 : latest-fftw ( -- path )
30 "https://ftp.fftw.org/pub/fftw/" [
32 parse-html find-links concat
33 [ name>> text = ] filter
35 [ "fftw-" head? ] filter
36 [ ".tar.gz" tail? ] filter
40 : build-fftw-dll ( -- )
44 { "cmake" "-G" "Visual Studio 17 2022" "-A" "Win32" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
45 qw{ msbuild fftw.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
47 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
48 qw{ msbuild fftw.sln /m /property:Configuration=Release } try-process
50 "Release/fftw3.dll" copy-output-file
51 ] with-build-directory
54 : winflexbison-versions ( -- seq )
55 "lexxmark" "winflexbison" "v" list-repository-tags-matching
56 tag-refs [ "v." head? ] reject human-sort ;
58 : build-winflexbison ( -- )
59 "lexxmark" "winflexbison" winflexbison-versions last [
61 qw{ cmake .. } try-process
62 qw{ cmake --build . --config Release --target package } try-process
63 ] with-build-directory
64 "bin/Release/win_bison.exe" "bison.exe" copy-vm-file-as
65 "bin/Release/win_flex.exe" "flex.exe" copy-vm-file-as
66 ] with-github-worktree-tag ;
68 : blas-versions ( -- seq )
69 "xianyi" "OpenBLAS" "v" list-repository-tags-matching
73 "xianyi" "OpenBLAS" blas-versions last [
76 { "cmake" "-G" "Visual Studio 17 2022" "-A" "Win32" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
77 qw{ msbuild OpenBLAS.sln /property:Configuration=Release /p:Platform=Win32 } try-process
79 { "cmake" "-G" "Visual Studio 17 2022" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
80 qw{ msbuild OpenBLAS.sln /property:Configuration=Release } try-process
82 "lib/RELEASE/openblas.dll" "blas.dll" copy-output-file-as
83 ] with-build-directory
84 ] with-github-worktree-tag ;
86 : openssl-versions ( -- seq )
87 "openssl" "openssl" "openssl-" list-repository-tags-matching
90 : build-openssl-32-dlls ( -- )
91 "openssl" "openssl" openssl-versions last [
93 "ProgramW6432" os-env program-files or
94 "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
97 qw{ perl Configure -DOPENSSL_PIC VC-WIN32 /FS } try-process
98 have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
99 { "libssl-3.dll" "libcrypto-3.dll" } copy-output-files
100 ] with-github-worktree-tag ;
102 : build-openssl-64-dlls ( -- )
103 "openssl" "openssl" openssl-versions last [
105 program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
108 qw{ perl Configure -DOPENSSL_PIC VC-WIN64A /FS } try-process
109 have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
110 { "apps/libssl-3-x64.dll" "apps/libcrypto-3-x64.dll" } copy-output-files
111 ] with-github-worktree-tag ;
113 : build-openssl-dlls ( -- )
114 32-bit? [ build-openssl-32-dlls ] [ build-openssl-64-dlls ] if ;
116 : cairo-versions ( -- version )
117 "https://gitlab.freedesktop.org/api/v4/projects/956/repository/tags"
118 http-get nip utf8 decode json> [ "name" of ] map ;
120 : build-cairo-dll ( -- )
121 "gitlab.freedesktop.org" "cairo" "cairo" cairo-versions first [
122 qw{ meson setup --force-fallback-for=freetype2,fontconfig,zlib,expat,expat_dep build } try-process
123 "build" prepend-current-path
124 [ { "ninja" } try-process ] with-directory
125 "." find-dlls copy-output-files
127 "gdbus-example-objectmanager.dll"
128 "moduletestplugin_a_library.dll"
129 "moduletestplugin_a_plugin.dll"
130 "moduletestplugin_b_library.dll"
131 "moduletestplugin_b_plugin.dll"
134 } delete-output-files
135 ] with-gitlab-worktree-tag ;
137 : latest-libressl ( -- path )
138 "https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/" [
139 http-get nip parse-html find-links concat
140 [ name>> text = ] filter
142 [ "libressl-" head? ] filter
143 [ ".tar.gz" tail? ] filter last
146 : build-libressl-dlls ( -- )
150 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
151 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
153 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
154 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
157 "crypto/Release/crypto-51.dll"
158 "ssl/Release/ssl-54.dll"
159 "tls/Release/tls-27.dll"
161 ] with-build-directory
164 : openal-versions ( -- seq )
165 "kcat" "openal-soft" "" list-repository-tags-matching
167 [ [ digit-or-dot? ] all? ] filter
170 : build-openal-dll ( -- )
171 "kcat" "openal-soft" openal-versions last [
176 "-G" "Visual Studio 17 2022"
178 "-DCMAKE_BUILD_TYPE=Release"
179 "-DBUILD_SHARED_LIBS=ON" ".."
181 qw{ msbuild OpenAL.sln /property:Configuration=Release /p:Platform=Win32 } try-process
185 "-G" "Visual Studio 17 2022"
186 "-DCMAKE_BUILD_TYPE=Release"
187 "-DBUILD_SHARED_LIBS=ON" ".."
189 qw{ msbuild OpenAL.sln /property:Configuration=Release } try-process
191 "Release/OpenAL32.dll" copy-output-file
192 ] with-build-directory
193 ] with-github-worktree-tag ;
195 : grpc-versions ( -- seq )
196 "grpc" "grpc" "v" list-repository-tags-matching
197 tag-refs human-sort ;
199 : build-grpc-dll ( -- )
200 "grpc" "grpc" grpc-versions last [
201 qw{ git submodule init } try-process
202 qw{ git submodule update } try-process
203 qw{ rm -rf third_party\boringssl-with-bazel } try-process
204 ! grpc has a file called BUILD so use build2
209 "-G" "Visual Studio 17 2022"
211 "-DCMAKE_BUILD_TYPE=Release"
212 "-DBUILD_SHARED_LIBS=ON" ".."
214 qw{ msbuild grpc.sln /property:Configuration=Release /p:Platform=Win32 } try-process
218 "-G" "Visual Studio 17 2022"
219 "-DCMAKE_BUILD_TYPE=Release"
220 "-DBUILD_SHARED_LIBS=ON" ".."
222 qw{ msbuild grpc.sln /property:Configuration=Release } try-process
224 "bin/Release/libprotobuf-lite.dll" copy-output-file
225 "bin/Release/libprotobuf.dll" copy-output-file
226 "bin/Release/libprotoc.dll" copy-output-file
227 "bin/Release/abseil_dll.dll" copy-output-file
228 "bin/Release/protoc.exe" copy-output-file
229 ] with-build-directory-as
230 ] with-github-worktree-tag ;
232 : latest-pcre-tar-gz ( -- path )
233 "https://ftp.exim.org/pub/pcre/" [
234 http-get nip parse-html find-links concat
235 [ name>> text = ] filter [ text>> ] map
236 [ "pcre-" head? ] filter
237 [ ".tar.gz" tail? ] filter last
240 : build-pcre-dll ( -- )
244 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
245 qw{ msbuild PCRE.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
247 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
248 qw{ msbuild PCRE.sln /m /property:Configuration=Release } try-process
250 "Release/pcre.dll" copy-output-file
251 ] with-build-directory
254 : pcre2-versions ( -- seq )
255 "PCRE2Project" "pcre2" "" list-repository-tags-matching
256 tag-refs human-sort ;
258 : build-pcre2-dll ( -- )
259 "PCRE2Project" "pcre2" pcre2-versions last [
262 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
263 qw{ msbuild PCRE2.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
265 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
266 qw{ msbuild PCRE2.sln /m /property:Configuration=Release } try-process
268 { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
269 ] with-build-directory
270 ] with-github-worktree-tag ;
272 : postgres-versions ( -- seq )
273 "postgres" "postgres" "REL_" list-repository-tags-matching
275 ! [ "_" split1-last nip [ digit? ] all? ] filter ! no RC1 or BETA1
278 ! choco install -y meson winflexbison3
279 : build-postgres-dll ( -- )
280 "postgres" "postgres" postgres-versions last [
281 "src/tools/msvc/clean.bat" prepend-current-path try-process
282 qw{ meson setup build } try-process
283 "build" prepend-current-path
284 [ { "ninja" } try-process ] with-directory
285 "build/src/interfaces/libpq/libpq.dll" copy-output-file
286 ] with-github-worktree-tag ;
288 : raylib-versions ( -- seq )
289 "raysan5" "raylib" "" list-repository-tags-matching
290 tag-refs human-sort ;
292 ! choco install -y glfw3
293 : build-raylib-dll ( -- )
294 "raysan5" "raylib" raylib-versions last [
297 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
298 qw{ msbuild raylib.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
300 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
301 qw{ msbuild raylib.sln /m /property:Configuration=Release } try-process
303 "raylib/Release/raylib.dll" copy-output-file
304 ] with-build-directory
305 ] with-github-worktree-tag ;
307 : raygui-versions ( -- seq )
308 "raysan5" "raygui" "" list-repository-tags-matching
309 tag-refs human-sort ;
311 :: build-raygui-dll ( -- )
312 "raysan5" "raygui" raygui-versions last [
313 "raysan5" "raylib" raylib-versions last github-tag-disk-checkout-path :> $raylib-dir
314 $raylib-dir "src" append-path :> $raylib-src
315 $raylib-dir "build/raylib/Release/raylib.lib" append-path :> $raylib-lib
317 "src/raygui.h" "src/raygui.c" copy-file
319 [ "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
321 [ "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
323 "raygui.dll" copy-output-file
324 ] with-github-worktree-tag ;
326 : ripgrep-versions ( -- seq )
327 "BurntSushi" "ripgrep" "" list-repository-tags-matching
329 [ [ digit-or-dot? ] all? ] filter
332 : build-ripgrep ( -- )
333 "BurntSushi" "ripgrep" ripgrep-versions last [
334 qw{ cargo build --release } try-process
335 "target/release/rg.exe" copy-output-file
336 ] with-github-worktree-tag ;
338 : snappy-versions ( -- seq )
339 "google" "snappy" "" list-repository-tags-matching
340 tag-refs human-sort ;
342 : build-snappy-dll ( -- )
343 "google" "snappy" snappy-versions last [
346 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
347 qw{ msbuild Snappy.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
349 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
350 qw{ msbuild Snappy.sln /m /property:Configuration=Release } try-process
352 "Release/snappy.dll" copy-output-file
353 ] with-build-directory
354 ] with-github-worktree-tag ;
356 : sqlite-versions ( -- seq )
357 "sqlite" "sqlite" "version-" list-repository-tags-matching
358 tag-refs human-sort ;
360 : build-sqlite-dll ( -- )
361 "sqlite" "sqlite" sqlite-versions last [
362 qw{ nmake /f Makefile.msc clean } try-process
363 qw{ nmake /f Makefile.msc } try-process
364 "sqlite3.dll" copy-output-file
365 ] with-github-worktree-tag ;
367 : duckdb-versions ( -- seq )
368 "duckdb" "duckdb" "v" list-repository-tags-matching
369 tag-refs human-sort ;
371 : build-duckdb-dll ( -- )
372 "duckdb" "duckdb" duckdb-versions last [
375 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
376 qw{ msbuild duckdb.sln /property:Configuration=Release /p:Platform=Win32 } try-process
378 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
379 qw{ msbuild duckdb.sln /property:Configuration=Release } try-process
381 "src/Release/duckdb.dll" copy-output-file
382 "Release/duckdb.exe" copy-output-file
383 ] with-build-directory
384 ] with-github-worktree-tag ;
386 : yaml-versions ( -- seq )
387 "yaml" "libyaml" "" list-repository-tags-matching
388 tag-refs [ [ digit-or-dot? ] all? ] filter human-sort ;
390 : build-yaml-dll ( -- )
391 "yaml" "libyaml" yaml-versions last [
394 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
395 qw{ msbuild yaml.sln /property:Configuration=Release /p:Platform=Win32 } try-process
397 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
398 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
401 "Release/yaml.dll" copy-output-file
402 ] with-build-directory
403 ] with-github-worktree-tag ;
405 : zeromq-versions ( -- seq )
406 "zeromq" "libzmq" "" list-repository-tags-matching
407 tag-refs human-sort ;
409 : build-zeromq-dll ( -- )
410 "zeromq" "libzmq" zeromq-versions last [
413 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
414 qw{ msbuild ZeroMQ.sln /property:Configuration=Release /p:Platform=Win32 } try-process
416 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
417 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
419 "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
420 ] with-build-directory
421 ] with-github-worktree-tag ;
423 : zlib-versions ( -- seq )
424 "madler" "zlib" "v" list-repository-tags-matching
425 tag-refs human-sort ;
427 : build-zlib-dll ( -- )
428 "madler" "zlib" zlib-versions last [
429 qw{ nmake /f win32/Makefile.msc clean } try-process
430 qw{ nmake /f win32/Makefile.msc } try-process
431 "zlib1.dll" copy-output-file
432 ] with-github-worktree-tag ;
434 : lz4-versions ( -- seq )
435 "lz4" "lz4" "v" list-repository-tags-matching
436 tag-refs human-sort ;
439 "lz4" "lz4" lz4-versions last [
443 qw{ cmake -A Win32 -DBUILD_SHARED_LIBS=ON .. } try-process
444 qw{ msbuild LZ4.sln /property:Configuration=Release /p:Platform=Win32 } try-process
446 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
447 qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
449 "Release/lz4.dll" copy-output-file
450 ] with-build-directory
452 ] with-github-worktree-tag ;
454 : zstd-versions ( -- seq )
455 "facebook" "zstd" "v" list-repository-tags-matching
465 : build-zstd-dll ( -- )
466 "facebook" "zstd" zstd-versions last [
470 --buildtype=debugoptimized
472 -Dauto_features=enabled
476 -Ddefault_library=both
485 --buildtype=debugoptimized
487 -Dauto_features=enabled
491 -Ddefault_library=both
496 "builddir" prepend-current-path
498 { "ninja" } try-process
499 "lib/zstd-1.dll" copy-output-file
501 ] with-github-worktree-tag ;
503 ! Probably not needed on Windows 10+
504 : install-windows-redistributable ( -- )
506 "https://aka.ms/vs/17/release/vc_redist.x64.exe" download
507 qw{ vc_redist.x64.exe /install /passive /norestart } try-process
508 ] with-temp-directory ;
510 : build-windows-dlls ( -- )
511 dll-out-directory make-directories
518 32-bit? [ build-postgres-dll ] unless
532 ! build-ripgrep build-duckdb