]> gitweb.factorcode.org Git - factor.git/blob - extra/build-from-source/windows/windows.factor
4282b9180325d3493e589ea81f1be84731ca9ac4
[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: 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
10
11 ! choco install -y meson StrawberryPerl nasm winflexbison3 glfw3 jom
12 ! jom is for building openssl in parallel
13
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 ;
18
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 ;
23
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 ;
28
29 : build-fftw-dll ( -- )
30     latest-fftw [
31         [
32             32-bit? [
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
35             ] [
36                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
37                 qw{ msbuild fftw.sln /m /property:Configuration=Release } try-process
38             ] if
39             "Release/fftw3.dll" copy-output-file
40         ] with-build-directory
41     ] with-tar-gz ;
42
43 : build-winflexbison ( -- )
44     "lexxmark" "winflexbison" winflexbison-versions last [
45         [
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 ;
52
53 : build-blas ( -- )
54     "xianyi" "OpenBLAS" blas-versions last [
55         [
56             32-bit? [
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
59             ] [
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
62             ] if
63             "lib/RELEASE/openblas.dll" "blas.dll" copy-output-file-as
64         ] with-build-directory
65     ] with-github-worktree-tag ;
66
67 : build-openssl-32-dlls ( -- )
68     "openssl" "openssl" openssl-versions last [
69         check-perl
70         "ProgramW6432" os-env program-files or
71             "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
72         check-nasm
73         check-nmake
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 ;
78
79 : build-openssl-64-dlls ( -- )
80     "openssl" "openssl" openssl-versions last [
81         check-perl
82         program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
83         check-nasm
84         check-nmake
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 ;
89
90 : build-openssl-dlls ( -- )
91     32-bit? [ build-openssl-32-dlls ] [ build-openssl-64-dlls ] if ;
92
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
99         {
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"
105             "testmodulea.dll"
106             "testmoduleb.dll"
107         } delete-output-files
108     ] with-gitlab-worktree-tag ;
109
110 : build-libressl-dlls ( -- )
111     latest-libressl [
112         [
113             32-bit? [
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
116             ] [
117                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
118                 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
119             ] if
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
124     ] with-tar-gz ;
125
126 : build-openal-dll ( -- )
127     "kcat" "openal-soft" openal-versions last [
128         [
129             32-bit? [
130                 {
131                     "cmake"
132                     "-G" "Visual Studio 17 2022"
133                     "-A" "Win32"
134                     "-DCMAKE_BUILD_TYPE=Release"
135                     "-DBUILD_SHARED_LIBS=ON" ".."
136                 } try-process
137                 qw{ msbuild OpenAL.sln /property:Configuration=Release /p:Platform=Win32 } try-process
138             ] [
139                 {
140                     "cmake"
141                     "-G" "Visual Studio 17 2022"
142                     "-DCMAKE_BUILD_TYPE=Release"
143                     "-DBUILD_SHARED_LIBS=ON" ".."
144                 } try-process
145                 qw{ msbuild OpenAL.sln /property:Configuration=Release } try-process
146             ] if
147             "Release/OpenAL32.dll" copy-output-file
148         ] with-build-directory
149     ] with-github-worktree-tag ;
150
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
157         "build2" [
158             32-bit? [
159                 {
160                     "cmake"
161                     "-G" "Visual Studio 17 2022"
162                     "-A" "Win32"
163                     "-DCMAKE_BUILD_TYPE=Release"
164                     "-DBUILD_SHARED_LIBS=ON" ".."
165                 } try-process
166                 qw{ msbuild grpc.sln /property:Configuration=Release /p:Platform=Win32 } try-process
167             ] [
168                 {
169                     "cmake"
170                     "-G" "Visual Studio 17 2022"
171                     "-DCMAKE_BUILD_TYPE=Release"
172                     "-DBUILD_SHARED_LIBS=ON" ".."
173                 } try-process
174                 qw{ msbuild grpc.sln /property:Configuration=Release } try-process
175             ] if
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 ;
183
184 : build-pcre-dll ( -- )
185     latest-pcre-tar-gz [
186         [
187             32-bit? [
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
190             ] [
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
193             ] if
194             "Release/pcre.dll" copy-output-file
195         ] with-build-directory
196     ] with-tar-gz ;
197
198 : build-pcre2-dll ( -- )
199     "PCRE2Project" "pcre2" pcre2-versions last [
200         [
201             32-bit? [
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
204             ] [
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
207             ] if
208             { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
209         ] with-build-directory
210     ] with-github-worktree-tag ;
211
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 ;
221
222 ! choco install -y glfw3
223 : build-raylib-dll ( -- )
224     "raysan5" "raylib" raylib-versions last [
225         [
226             32-bit? [
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
229             ] [
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
232             ] if
233             "raylib/Release/raylib.dll" copy-output-file
234         ] with-build-directory
235     ] with-github-worktree-tag ;
236
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
242
243         "src/raygui.h" "src/raygui.c" copy-file
244         32-bit? [
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
246         ] [
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
248         ] if
249         "raygui.dll" copy-output-file
250     ] with-github-worktree-tag ;
251
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 ;
257
258 : build-snappy-dll ( -- )
259     "google" "snappy" snappy-versions last [
260         [
261             32-bit? [
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
264             ] [
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
267             ] if
268             "Release/snappy.dll" copy-output-file
269         ] with-build-directory
270     ] with-github-worktree-tag ;
271
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 ;
278
279 : build-duckdb-dll ( -- )
280     "duckdb" "duckdb" duckdb-versions last [
281         [
282             32-bit? [
283                 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
284                 qw{ msbuild duckdb.sln /property:Configuration=Release /p:Platform=Win32 } try-process
285             ] [
286                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
287                 qw{ msbuild duckdb.sln /property:Configuration=Release } try-process
288             ] if
289             "src/Release/duckdb.dll" copy-output-file
290             "Release/duckdb.exe" copy-output-file
291         ] with-build-directory
292     ] with-github-worktree-tag ;
293
294 : build-yaml-dll ( -- )
295     "yaml" "libyaml" yaml-versions last [
296         [
297             32-bit? [
298                 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
299                 qw{ msbuild yaml.sln /property:Configuration=Release /p:Platform=Win32 } try-process
300             ] [
301                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
302                 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
303             ] if
304
305             "Release/yaml.dll" copy-output-file
306         ] with-build-directory
307     ] with-github-worktree-tag ;
308
309 : build-zeromq-dll ( -- )
310     "zeromq" "libzmq" zeromq-versions last [
311         [
312             32-bit? [
313                 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
314                 qw{ msbuild ZeroMQ.sln /property:Configuration=Release /p:Platform=Win32 } try-process
315             ] [
316                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
317                 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
318             ] if
319             "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
320         ] with-build-directory
321     ] with-github-worktree-tag ;
322
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 ;
329
330 : build-lz4 ( -- )
331     "lz4" "lz4" lz4-versions last [
332         "build/cmake" [
333             [
334                 32-bit? [
335                     qw{ cmake -A Win32 -DBUILD_SHARED_LIBS=ON .. } try-process
336                     qw{ msbuild LZ4.sln /property:Configuration=Release /p:Platform=Win32 } try-process
337                 ] [
338                     qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
339                     qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
340                 ] if
341                 "Release/lz4.dll" copy-output-file
342             ] with-build-directory
343         ] with-directory
344     ] with-github-worktree-tag ;
345
346 : build-zstd-dll ( -- )
347     "facebook" "zstd" zstd-versions last [
348         32-bit? [
349             qw{
350                 meson setup
351                 --buildtype=debugoptimized
352                 -Db_lundef=false
353                 -Dauto_features=enabled
354                 -Dbin_programs=true
355                 -Dbin_tests=true
356                 -Dbin_contrib=true
357                 -Ddefault_library=both
358                 -Dlz4=disabled
359                 -Dlzma=disabled
360                 -Dzlib=disabled
361                 build/meson builddir
362             } try-process
363         ] [
364             qw{
365                 meson setup
366                 --buildtype=debugoptimized
367                 -Db_lundef=false
368                 -Dauto_features=enabled
369                 -Dbin_programs=true
370                 -Dbin_tests=true
371                 -Dbin_contrib=true
372                 -Ddefault_library=both
373                 -Dlz4=disabled
374                 build/meson builddir
375             } try-process
376         ] if
377         "builddir" prepend-current-path
378         [
379             { "ninja" } try-process
380             "lib/zstd-1.dll" copy-output-file
381         ] with-directory
382     ] with-github-worktree-tag ;
383
384 ! Probably not needed on Windows 10+
385 : install-windows-redistributable ( -- )
386     [
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 ;
390
391 : build-windows-dlls ( -- )
392     dll-out-directory make-directories
393     build-winflexbison
394     build-openssl-dlls
395     build-blas
396     build-lz4
397     build-openal-dll
398     build-pcre2-dll
399     32-bit? [ build-postgres-dll ] unless
400     build-raylib-dll
401     build-raygui-dll
402     build-snappy-dll
403     build-sqlite-dll
404     build-yaml-dll
405     build-zeromq-dll
406     build-zlib-dll
407     build-zstd-dll
408     build-cairo-dll
409     build-libressl-dlls
410     build-fftw-dll
411     build-pcre-dll ;
412
413 ! build-ripgrep build-duckdb