]> gitweb.factorcode.org Git - factor.git/blob - extra/build-from-source/windows/windows.factor
7cd6a5dd85c86b05b85bf50ea2a2f0b42bac6b96
[factor.git] / extra / build-from-source / windows / windows.factor
1 ! Copyright (C) 2023 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: build-from-source combinators.smart continuations
4 environment http.client io.directories io.files.temp io.launcher
5 io.pathnames kernel layouts qw sequences windows.shell32 ;
6 IN: build-from-source.windows
7
8 ! choco install -y meson StrawberryPerl nasm winflexbison3 glfw3 jom
9 ! jom is for building openssl in parallel
10
11 ! From `choco install -y nasm`
12 ! Add nasm to path (windows+r sysdm.cpl -> Advanced tab -> Environment Variables -> New -> "c:\Program Files\NASM")
13 : check-nasm ( -- ) { "nasm.exe" "-h" } try-process ;
14 : have-jom? ( -- ? ) [ { "jom" } try-process t ] [ drop f ] recover ;
15
16 ! From `choco install -y StrawberryPerl`
17 ! make sure it is above the git /usr/bin/perl (if that is installed)
18 ! TODO: https://stackoverflow.com/questions/5898131/set-a-persistent-environment-variable-from-cmd-exe
19 : check-perl ( -- ) { "perl" "-h" } try-process ;
20
21 ! From vcvarsall.bat (x64 Native Tools Command Prompt runs this automatically)
22 : check-nmake ( -- ) { "nmake" "/?" } try-process ;
23 : check-cmake ( -- ) { "cmake" "-h" } try-process ;
24 : check-msbuild ( -- ) { "msbuild" "-h" } try-process ;
25
26 : build-fftw-dll ( -- )
27     latest-fftw [
28         [
29             32-bit? [
30                 { "cmake" "-G" "Visual Studio 17 2022" "-A" "Win32" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
31                 qw{ msbuild fftw.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
32             ] [
33                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
34                 qw{ msbuild fftw.sln /m /property:Configuration=Release } try-process
35             ] if
36             "Release/fftw3.dll" copy-output-file
37         ] with-build-directory
38     ] with-tar-gz ;
39
40 : build-winflexbison ( -- )
41     "lexxmark" "winflexbison" winflexbison-versions last [
42         [
43             qw{ cmake .. } try-process
44             qw{ cmake --build . --config Release --target package } try-process
45         ] with-build-directory
46         "bin/Release/win_bison.exe" "bison.exe" copy-vm-file-as
47         "bin/Release/win_flex.exe" "flex.exe" copy-vm-file-as
48     ] with-github-worktree-tag ;
49
50 : build-blas ( -- )
51     "xianyi" "OpenBLAS" blas-versions last [
52         [
53             32-bit? [
54                 { "cmake" "-G" "Visual Studio 17 2022" "-A" "Win32" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
55                 qw{ msbuild OpenBLAS.sln /property:Configuration=Release /p:Platform=Win32 } try-process
56             ] [
57                 { "cmake" "-G" "Visual Studio 17 2022" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
58                 qw{ msbuild OpenBLAS.sln /property:Configuration=Release } try-process
59             ] if
60             "lib/RELEASE/openblas.dll" "blas.dll" copy-output-file-as
61         ] with-build-directory
62     ] with-github-worktree-tag ;
63
64 : build-openssl-32-dlls ( -- )
65     "openssl" "openssl" openssl-versions last [
66         check-perl
67         "ProgramW6432" os-env program-files or
68             "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
69         check-nasm
70         check-nmake
71         qw{ perl Configure -DOPENSSL_PIC VC-WIN32 /FS } try-process
72         have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
73         { "libssl-3.dll" "libcrypto-3.dll" } copy-output-files
74     ] with-github-worktree-tag ;
75
76 : build-openssl-64-dlls ( -- )
77     "openssl" "openssl" openssl-versions last [
78         check-perl
79         program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
80         check-nasm
81         check-nmake
82         qw{ perl Configure -DOPENSSL_PIC VC-WIN64A /FS } try-process
83         have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
84         { "apps/libssl-3-x64.dll" "apps/libcrypto-3-x64.dll" } copy-output-files
85     ] with-github-worktree-tag ;
86
87 : build-openssl-dlls ( -- )
88     32-bit? [ build-openssl-32-dlls ] [ build-openssl-64-dlls ] if ;
89
90 : build-cairo-dll ( -- )
91     "gitlab.freedesktop.org" "cairo" "cairo" cairo-versions first [
92         qw{ meson setup --force-fallback-for=freetype2,fontconfig,zlib,expat,expat_dep build } try-process
93         "build" prepend-current-path
94         [ { "ninja" } try-process ] with-directory
95         "." find-dlls copy-output-files
96         {
97             "gdbus-example-objectmanager.dll"
98             "moduletestplugin_a_library.dll"
99             "moduletestplugin_a_plugin.dll"
100             "moduletestplugin_b_library.dll"
101             "moduletestplugin_b_plugin.dll"
102             "testmodulea.dll"
103             "testmoduleb.dll"
104         } delete-output-files
105     ] with-gitlab-worktree-tag ;
106
107 : build-libressl-dlls ( -- )
108     latest-libressl [
109         [
110             32-bit? [
111                 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
112                 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
113             ] [
114                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
115                 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
116             ] if
117             "crypto/Release/crypto.dll" "libressl-crypto.dll" copy-output-file-as
118             "ssl/Release/ssl.dll" "libressl-ssl.dll" copy-output-file-as
119             "tls/Release/tls.dll" "libressl-tls.dll" copy-output-file-as
120         ] with-build-directory
121     ] with-tar-gz ;
122
123 : build-openal-dll ( -- )
124     "kcat" "openal-soft" openal-versions last [
125         [
126             32-bit? [
127                 {
128                     "cmake"
129                     "-G" "Visual Studio 17 2022"
130                     "-A" "Win32"
131                     "-DCMAKE_BUILD_TYPE=Release"
132                     "-DBUILD_SHARED_LIBS=ON" ".."
133                 } try-process
134                 qw{ msbuild OpenAL.sln /property:Configuration=Release /p:Platform=Win32 } try-process
135             ] [
136                 {
137                     "cmake"
138                     "-G" "Visual Studio 17 2022"
139                     "-DCMAKE_BUILD_TYPE=Release"
140                     "-DBUILD_SHARED_LIBS=ON" ".."
141                 } try-process
142                 qw{ msbuild OpenAL.sln /property:Configuration=Release } try-process
143             ] if
144             "Release/OpenAL32.dll" copy-output-file
145         ] with-build-directory
146     ] with-github-worktree-tag ;
147
148 : build-grpc-dll ( -- )
149     "grpc" "grpc" grpc-versions last [
150         qw{ git submodule init } try-process
151         qw{ git submodule update } try-process
152         qw{ rm -rf third_party\boringssl-with-bazel } try-process
153         ! grpc has a file called BUILD so use build2
154         "build2" [
155             32-bit? [
156                 {
157                     "cmake"
158                     "-G" "Visual Studio 17 2022"
159                     "-A" "Win32"
160                     "-DCMAKE_BUILD_TYPE=Release"
161                     "-DBUILD_SHARED_LIBS=ON" ".."
162                 } try-process
163                 qw{ msbuild grpc.sln /property:Configuration=Release /p:Platform=Win32 } try-process
164             ] [
165                 {
166                     "cmake"
167                     "-G" "Visual Studio 17 2022"
168                     "-DCMAKE_BUILD_TYPE=Release"
169                     "-DBUILD_SHARED_LIBS=ON" ".."
170                 } try-process
171                 qw{ msbuild grpc.sln /property:Configuration=Release } try-process
172             ] if
173             "bin/Release/libprotobuf-lite.dll" copy-output-file
174             "bin/Release/libprotobuf.dll" copy-output-file
175             "bin/Release/libprotoc.dll" copy-output-file
176             "bin/Release/abseil_dll.dll" copy-output-file
177             "bin/Release/protoc.exe" copy-output-file
178         ] with-build-directory-as
179     ] with-github-worktree-tag ;
180
181 : build-pcre-dll ( -- )
182     latest-pcre-tar-gz [
183         [
184             32-bit? [
185                 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
186                 qw{ msbuild PCRE.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
187             ] [
188                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
189                 qw{ msbuild PCRE.sln /m /property:Configuration=Release } try-process
190             ] if
191             "Release/pcre.dll" copy-output-file
192         ] with-build-directory
193     ] with-tar-gz ;
194
195 : build-pcre2-dll ( -- )
196     "PCRE2Project" "pcre2" pcre2-versions last [
197         [
198             32-bit? [
199                 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
200                 qw{ msbuild PCRE2.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
201             ] [
202                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
203                 qw{ msbuild PCRE2.sln /m /property:Configuration=Release } try-process
204             ] if
205             { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
206         ] with-build-directory
207     ] with-github-worktree-tag ;
208
209 ! choco install -y meson winflexbison3
210 : build-postgres-dll ( -- )
211     "postgres" "postgres" postgres-versions last [
212         "src/tools/msvc/clean.bat" prepend-current-path try-process
213         qw{ meson setup build } try-process
214         "build" prepend-current-path
215         [ { "ninja" } try-process ] with-directory
216         "build/src/interfaces/libpq/libpq.dll" copy-output-file
217     ] with-github-worktree-tag ;
218
219 ! choco install -y glfw3
220 : build-raylib-dll ( -- )
221     "raysan5" "raylib" raylib-versions last [
222         [
223             32-bit? [
224                 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
225                 qw{ msbuild raylib.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
226             ] [
227                 qw{ cmake -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 } try-process
229             ] if
230             "raylib/Release/raylib.dll" copy-output-file
231         ] with-build-directory
232     ] with-github-worktree-tag ;
233
234 :: build-raygui-dll ( -- )
235     "raysan5" "raygui" raygui-versions last [
236         "raysan5" "raylib" raylib-versions last github-tag-disk-checkout-path :> $raylib-dir
237         $raylib-dir "src" append-path :> $raylib-src
238         $raylib-dir "build/raylib/Release/raylib.lib" append-path :> $raylib-lib
239
240         "src/raygui.h" "src/raygui.c" copy-file
241         32-bit? [
242             [ "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
243         ] [
244             [ "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
245         ] if
246         "raygui.dll" copy-output-file
247     ] with-github-worktree-tag ;
248
249 : build-ripgrep ( -- )
250     "BurntSushi" "ripgrep" ripgrep-versions last [
251         qw{ cargo +nightly build --release --features pcre2,simd-accel } try-process
252         "target/release/rg.exe" copy-output-file
253     ] with-github-worktree-tag ;
254
255 : build-snappy-dll ( -- )
256     "google" "snappy" snappy-versions last [
257         [
258             32-bit? [
259                 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
260                 qw{ msbuild Snappy.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
261             ] [
262                 qw{ cmake -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 } try-process
264             ] if
265             "Release/snappy.dll" copy-output-file
266         ] with-build-directory
267     ] with-github-worktree-tag ;
268
269 : build-sqlite-dll ( -- )
270     "sqlite" "sqlite" sqlite-versions last [
271         qw{ nmake /f Makefile.msc clean } try-process
272         qw{ nmake /f Makefile.msc } try-process
273         "sqlite3.dll" copy-output-file
274     ] with-github-worktree-tag ;
275
276 : build-duckdb-dll ( -- )
277     "duckdb" "duckdb" duckdb-versions last [
278         [
279             32-bit? [
280                 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
281                 qw{ msbuild duckdb.sln /property:Configuration=Release /p:Platform=Win32 } try-process
282             ] [
283                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
284                 qw{ msbuild duckdb.sln /property:Configuration=Release } try-process
285             ] if
286             "src/Release/duckdb.dll" copy-output-file
287             "Release/duckdb.exe" copy-output-file
288         ] with-build-directory
289     ] with-github-worktree-tag ;
290
291 : build-yaml-dll ( -- )
292     "yaml" "libyaml" yaml-versions last [
293         [
294             32-bit? [
295                 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
296                 qw{ msbuild yaml.sln /property:Configuration=Release /p:Platform=Win32 } try-process
297             ] [
298                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
299                 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
300             ] if
301
302             "Release/yaml.dll" copy-output-file
303         ] with-build-directory
304     ] with-github-worktree-tag ;
305
306 : build-zeromq-dll ( -- )
307     "zeromq" "libzmq" zeromq-versions last [
308         [
309             32-bit? [
310                 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
311                 qw{ msbuild ZeroMQ.sln /property:Configuration=Release /p:Platform=Win32 } try-process
312             ] [
313                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
314                 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
315             ] if
316             "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
317         ] with-build-directory
318     ] with-github-worktree-tag ;
319
320 : build-zlib-dll ( -- )
321     "madler" "zlib" zlib-versions last [
322         qw{ nmake /f win32/Makefile.msc clean } try-process
323         qw{ nmake /f win32/Makefile.msc } try-process
324         "zlib1.dll" copy-output-file
325     ] with-github-worktree-tag ;
326
327 : build-lz4 ( -- )
328     "lz4" "lz4" lz4-versions last [
329         "build/cmake" [
330             [
331                 32-bit? [
332                     qw{ cmake -A Win32 -DBUILD_SHARED_LIBS=ON .. } try-process
333                     qw{ msbuild LZ4.sln /property:Configuration=Release /p:Platform=Win32 } try-process
334                 ] [
335                     qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
336                     qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
337                 ] if
338                 "Release/lz4.dll" copy-output-file
339             ] with-build-directory
340         ] with-directory
341     ] with-github-worktree-tag ;
342
343 : build-zstd-dll ( -- )
344     "facebook" "zstd" zstd-versions last [
345         32-bit? [
346             qw{
347                 meson setup
348                 --buildtype=debugoptimized
349                 -Db_lundef=false
350                 -Dauto_features=enabled
351                 -Dbin_programs=true
352                 -Dbin_tests=true
353                 -Dbin_contrib=true
354                 -Ddefault_library=both
355                 -Dlz4=disabled
356                 -Dlzma=disabled
357                 -Dzlib=disabled
358                 build/meson builddir
359             } try-process
360         ] [
361             qw{
362                 meson setup
363                 --buildtype=debugoptimized
364                 -Db_lundef=false
365                 -Dauto_features=enabled
366                 -Dbin_programs=true
367                 -Dbin_tests=true
368                 -Dbin_contrib=true
369                 -Ddefault_library=both
370                 -Dlz4=disabled
371                 build/meson builddir
372             } try-process
373         ] if
374         "builddir" prepend-current-path
375         [
376             { "ninja" } try-process
377             "lib/zstd-1.dll" copy-output-file
378         ] with-directory
379     ] with-github-worktree-tag ;
380
381 ! Probably not needed on Windows 10+
382 : install-windows-redistributable ( -- )
383     [
384         "https://aka.ms/vs/17/release/vc_redist.x64.exe" download
385         qw{ vc_redist.x64.exe /install /passive /norestart } try-process
386     ] with-temp-directory ;
387
388 : build-windows-dlls ( -- )
389     dll-out-directory make-directories
390     build-winflexbison
391     build-openssl-dlls
392     build-blas
393     build-lz4
394     build-openal-dll
395     build-pcre2-dll
396     32-bit? [ build-postgres-dll ] unless
397     build-raylib-dll
398     build-raygui-dll
399     build-snappy-dll
400     build-sqlite-dll
401     build-yaml-dll
402     build-zeromq-dll
403     build-zlib-dll
404     build-zstd-dll
405     build-cairo-dll
406     build-libressl-dlls
407     build-fftw-dll
408     build-pcre-dll ;
409
410 : build-unused-windows-dlls ( -- )
411     dll-out-directory make-directories
412     build-grpc-dll
413     rustup-update
414     build-ripgrep
415     build-duckdb-dll ;