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
156 "crypto/Release/crypto.dll" "libressl-crypto.dll" copy-output-file-as
157 "ssl/Release/ssl.dll" "libressl-ssl.dll" copy-output-file-as
158 "tls/Release/tls.dll" "libressl-tls.dll" copy-output-file-as
159 ] with-build-directory
162 : openal-versions ( -- seq )
163 "kcat" "openal-soft" "" list-repository-tags-matching
165 [ [ digit-or-dot? ] all? ] filter
168 : build-openal-dll ( -- )
169 "kcat" "openal-soft" openal-versions last [
174 "-G" "Visual Studio 17 2022"
176 "-DCMAKE_BUILD_TYPE=Release"
177 "-DBUILD_SHARED_LIBS=ON" ".."
179 qw{ msbuild OpenAL.sln /property:Configuration=Release /p:Platform=Win32 } try-process
183 "-G" "Visual Studio 17 2022"
184 "-DCMAKE_BUILD_TYPE=Release"
185 "-DBUILD_SHARED_LIBS=ON" ".."
187 qw{ msbuild OpenAL.sln /property:Configuration=Release } try-process
189 "Release/OpenAL32.dll" copy-output-file
190 ] with-build-directory
191 ] with-github-worktree-tag ;
193 : grpc-versions ( -- seq )
194 "grpc" "grpc" "v" list-repository-tags-matching
195 tag-refs human-sort ;
197 : build-grpc-dll ( -- )
198 "grpc" "grpc" grpc-versions last [
199 qw{ git submodule init } try-process
200 qw{ git submodule update } try-process
201 qw{ rm -rf third_party\boringssl-with-bazel } try-process
202 ! grpc has a file called BUILD so use build2
207 "-G" "Visual Studio 17 2022"
209 "-DCMAKE_BUILD_TYPE=Release"
210 "-DBUILD_SHARED_LIBS=ON" ".."
212 qw{ msbuild grpc.sln /property:Configuration=Release /p:Platform=Win32 } try-process
216 "-G" "Visual Studio 17 2022"
217 "-DCMAKE_BUILD_TYPE=Release"
218 "-DBUILD_SHARED_LIBS=ON" ".."
220 qw{ msbuild grpc.sln /property:Configuration=Release } try-process
222 "bin/Release/libprotobuf-lite.dll" copy-output-file
223 "bin/Release/libprotobuf.dll" copy-output-file
224 "bin/Release/libprotoc.dll" copy-output-file
225 "bin/Release/abseil_dll.dll" copy-output-file
226 "bin/Release/protoc.exe" copy-output-file
227 ] with-build-directory-as
228 ] with-github-worktree-tag ;
230 : latest-pcre-tar-gz ( -- path )
231 "https://ftp.exim.org/pub/pcre/" [
232 http-get nip parse-html find-links concat
233 [ name>> text = ] filter [ text>> ] map
234 [ "pcre-" head? ] filter
235 [ ".tar.gz" tail? ] filter last
238 : build-pcre-dll ( -- )
242 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
243 qw{ msbuild PCRE.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
245 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
246 qw{ msbuild PCRE.sln /m /property:Configuration=Release } try-process
248 "Release/pcre.dll" copy-output-file
249 ] with-build-directory
252 : pcre2-versions ( -- seq )
253 "PCRE2Project" "pcre2" "" list-repository-tags-matching
254 tag-refs human-sort ;
256 : build-pcre2-dll ( -- )
257 "PCRE2Project" "pcre2" pcre2-versions last [
260 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
261 qw{ msbuild PCRE2.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
263 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
264 qw{ msbuild PCRE2.sln /m /property:Configuration=Release } try-process
266 { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
267 ] with-build-directory
268 ] with-github-worktree-tag ;
270 : postgres-versions ( -- seq )
271 "postgres" "postgres" "REL_" list-repository-tags-matching
273 ! [ "_" split1-last nip [ digit? ] all? ] filter ! no RC1 or BETA1
276 ! choco install -y meson winflexbison3
277 : build-postgres-dll ( -- )
278 "postgres" "postgres" postgres-versions last [
279 "src/tools/msvc/clean.bat" prepend-current-path try-process
280 qw{ meson setup build } try-process
281 "build" prepend-current-path
282 [ { "ninja" } try-process ] with-directory
283 "build/src/interfaces/libpq/libpq.dll" copy-output-file
284 ] with-github-worktree-tag ;
286 : raylib-versions ( -- seq )
287 "raysan5" "raylib" "" list-repository-tags-matching
288 tag-refs human-sort ;
290 ! choco install -y glfw3
291 : build-raylib-dll ( -- )
292 "raysan5" "raylib" raylib-versions last [
295 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
296 qw{ msbuild raylib.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
298 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
299 qw{ msbuild raylib.sln /m /property:Configuration=Release } try-process
301 "raylib/Release/raylib.dll" copy-output-file
302 ] with-build-directory
303 ] with-github-worktree-tag ;
305 : raygui-versions ( -- seq )
306 "raysan5" "raygui" "" list-repository-tags-matching
307 tag-refs human-sort ;
309 :: build-raygui-dll ( -- )
310 "raysan5" "raygui" raygui-versions last [
311 "raysan5" "raylib" raylib-versions last github-tag-disk-checkout-path :> $raylib-dir
312 $raylib-dir "src" append-path :> $raylib-src
313 $raylib-dir "build/raylib/Release/raylib.lib" append-path :> $raylib-lib
315 "src/raygui.h" "src/raygui.c" copy-file
317 [ "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
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:x64" ] output>array try-process
321 "raygui.dll" copy-output-file
322 ] with-github-worktree-tag ;
324 : ripgrep-versions ( -- seq )
325 "BurntSushi" "ripgrep" "" list-repository-tags-matching
327 [ [ digit-or-dot? ] all? ] filter
330 : build-ripgrep ( -- )
331 "BurntSushi" "ripgrep" ripgrep-versions last [
332 qw{ cargo build --release } try-process
333 "target/release/rg.exe" copy-output-file
334 ] with-github-worktree-tag ;
336 : snappy-versions ( -- seq )
337 "google" "snappy" "" list-repository-tags-matching
338 tag-refs human-sort ;
340 : build-snappy-dll ( -- )
341 "google" "snappy" snappy-versions last [
344 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
345 qw{ msbuild Snappy.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
347 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
348 qw{ msbuild Snappy.sln /m /property:Configuration=Release } try-process
350 "Release/snappy.dll" copy-output-file
351 ] with-build-directory
352 ] with-github-worktree-tag ;
354 : sqlite-versions ( -- seq )
355 "sqlite" "sqlite" "version-" list-repository-tags-matching
356 tag-refs human-sort ;
358 : build-sqlite-dll ( -- )
359 "sqlite" "sqlite" sqlite-versions last [
360 qw{ nmake /f Makefile.msc clean } try-process
361 qw{ nmake /f Makefile.msc } try-process
362 "sqlite3.dll" copy-output-file
363 ] with-github-worktree-tag ;
365 : duckdb-versions ( -- seq )
366 "duckdb" "duckdb" "v" list-repository-tags-matching
367 tag-refs human-sort ;
369 : build-duckdb-dll ( -- )
370 "duckdb" "duckdb" duckdb-versions last [
373 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
374 qw{ msbuild duckdb.sln /property:Configuration=Release /p:Platform=Win32 } try-process
376 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
377 qw{ msbuild duckdb.sln /property:Configuration=Release } try-process
379 "src/Release/duckdb.dll" copy-output-file
380 "Release/duckdb.exe" copy-output-file
381 ] with-build-directory
382 ] with-github-worktree-tag ;
384 : yaml-versions ( -- seq )
385 "yaml" "libyaml" "" list-repository-tags-matching
386 tag-refs [ [ digit-or-dot? ] all? ] filter human-sort ;
388 : build-yaml-dll ( -- )
389 "yaml" "libyaml" yaml-versions last [
392 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
393 qw{ msbuild yaml.sln /property:Configuration=Release /p:Platform=Win32 } try-process
395 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
396 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
399 "Release/yaml.dll" copy-output-file
400 ] with-build-directory
401 ] with-github-worktree-tag ;
403 : zeromq-versions ( -- seq )
404 "zeromq" "libzmq" "" list-repository-tags-matching
405 tag-refs human-sort ;
407 : build-zeromq-dll ( -- )
408 "zeromq" "libzmq" zeromq-versions last [
411 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
412 qw{ msbuild ZeroMQ.sln /property:Configuration=Release /p:Platform=Win32 } try-process
414 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
415 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
417 "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
418 ] with-build-directory
419 ] with-github-worktree-tag ;
421 : zlib-versions ( -- seq )
422 "madler" "zlib" "v" list-repository-tags-matching
423 tag-refs human-sort ;
425 : build-zlib-dll ( -- )
426 "madler" "zlib" zlib-versions last [
427 qw{ nmake /f win32/Makefile.msc clean } try-process
428 qw{ nmake /f win32/Makefile.msc } try-process
429 "zlib1.dll" copy-output-file
430 ] with-github-worktree-tag ;
432 : lz4-versions ( -- seq )
433 "lz4" "lz4" "v" list-repository-tags-matching
434 tag-refs human-sort ;
437 "lz4" "lz4" lz4-versions last [
441 qw{ cmake -A Win32 -DBUILD_SHARED_LIBS=ON .. } try-process
442 qw{ msbuild LZ4.sln /property:Configuration=Release /p:Platform=Win32 } try-process
444 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
445 qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
447 "Release/lz4.dll" copy-output-file
448 ] with-build-directory
450 ] with-github-worktree-tag ;
452 : zstd-versions ( -- seq )
453 "facebook" "zstd" "v" list-repository-tags-matching
463 : build-zstd-dll ( -- )
464 "facebook" "zstd" zstd-versions last [
468 --buildtype=debugoptimized
470 -Dauto_features=enabled
474 -Ddefault_library=both
483 --buildtype=debugoptimized
485 -Dauto_features=enabled
489 -Ddefault_library=both
494 "builddir" prepend-current-path
496 { "ninja" } try-process
497 "lib/zstd-1.dll" copy-output-file
499 ] with-github-worktree-tag ;
501 ! Probably not needed on Windows 10+
502 : install-windows-redistributable ( -- )
504 "https://aka.ms/vs/17/release/vc_redist.x64.exe" download
505 qw{ vc_redist.x64.exe /install /passive /norestart } try-process
506 ] with-temp-directory ;
508 : build-windows-dlls ( -- )
509 dll-out-directory make-directories
516 32-bit? [ build-postgres-dll ] unless
530 ! build-ripgrep build-duckdb