]> gitweb.factorcode.org Git - factor.git/blob - extra/build-from-source/windows/windows.factor
build-from-source: exclude RC (release candidate) versions
[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-capnproto-dll ( -- )
65     "capnproto" "capnproto" capnproto-versions last [
66         [
67             32-bit? [
68                 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
69                 { "msbuild" "Cap'n Proto Root.sln" "/m" "/property:Configuration=Release" "/p:Platform=Win32" } try-process
70             ] [
71                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
72                 { "msbuild" "Cap'n Proto Root.sln" "/m" "/property:Configuration=Release" } try-process
73             ] if
74             ! "raylib/Release/raylib.dll" copy-output-file
75         ] with-build-directory
76     ] with-github-worktree-tag ;
77
78
79 : build-openssl-32-dlls ( -- )
80     "openssl" "openssl" openssl-release-versions last [
81         check-perl
82         "ProgramW6432" os-env program-files or
83             "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
84         check-nasm
85         check-nmake
86         qw{ perl Configure -DOPENSSL_PIC VC-WIN32 /FS } try-process
87         have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
88         { "libssl-3.dll" "libcrypto-3.dll" } copy-output-files
89     ] with-github-worktree-tag ;
90
91 : build-openssl-64-dlls ( -- )
92     "openssl" "openssl" openssl-release-versions last [
93         check-perl
94         program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
95         check-nasm
96         check-nmake
97         qw{ perl Configure -DOPENSSL_PIC VC-WIN64A /FS } try-process
98         have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
99         { "apps/libssl-3-x64.dll" "apps/libcrypto-3-x64.dll" } copy-output-files
100     ] with-github-worktree-tag ;
101
102 : build-openssl-dlls ( -- )
103     32-bit? [ build-openssl-32-dlls ] [ build-openssl-64-dlls ] if ;
104
105 : build-cairo-dll ( -- )
106     "gitlab.freedesktop.org" "cairo" "cairo" cairo-versions first [
107         qw{ meson setup --force-fallback-for=freetype2,fontconfig,zlib,expat,expat_dep build } try-process
108         "build" prepend-current-path
109         [ { "ninja" } try-process ] with-directory
110         "." find-dlls copy-output-files
111         {
112             "gdbus-example-objectmanager.dll"
113             "moduletestplugin_a_library.dll"
114             "moduletestplugin_a_plugin.dll"
115             "moduletestplugin_b_library.dll"
116             "moduletestplugin_b_plugin.dll"
117             "testmodulea.dll"
118             "testmoduleb.dll"
119         } delete-output-files
120     ] with-gitlab-worktree-tag ;
121
122 : build-libressl-dlls ( -- )
123     latest-libressl [
124         [
125             32-bit? [
126                 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
127                 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
128             ] [
129                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
130                 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
131             ] if
132             "crypto/Release/crypto.dll" "libressl-crypto.dll" copy-output-file-as
133             "ssl/Release/ssl.dll" "libressl-ssl.dll" copy-output-file-as
134             "tls/Release/tls.dll" "libressl-tls.dll" copy-output-file-as
135         ] with-build-directory
136     ] with-tar-gz ;
137
138 : build-openal-dll ( -- )
139     "kcat" "openal-soft" openal-versions last [
140         [
141             32-bit? [
142                 {
143                     "cmake"
144                     "-G" "Visual Studio 17 2022"
145                     "-A" "Win32"
146                     "-DCMAKE_BUILD_TYPE=Release"
147                     "-DBUILD_SHARED_LIBS=ON" ".."
148                 } try-process
149                 qw{ msbuild OpenAL.sln /property:Configuration=Release /p:Platform=Win32 } try-process
150             ] [
151                 {
152                     "cmake"
153                     "-G" "Visual Studio 17 2022"
154                     "-DCMAKE_BUILD_TYPE=Release"
155                     "-DBUILD_SHARED_LIBS=ON" ".."
156                 } try-process
157                 qw{ msbuild OpenAL.sln /property:Configuration=Release } try-process
158             ] if
159             "Release/OpenAL32.dll" copy-output-file
160         ] with-build-directory
161     ] with-github-worktree-tag ;
162
163 : build-grpc-dll ( -- )
164     "grpc" "grpc" grpc-versions last [
165         qw{ git submodule init } try-process
166         qw{ git submodule update } try-process
167         qw{ rm -rf third_party\boringssl-with-bazel } try-process
168         ! grpc has a file called BUILD so use build2
169         "build2" [
170             32-bit? [
171                 {
172                     "cmake"
173                     "-G" "Visual Studio 17 2022"
174                     "-A" "Win32"
175                     "-DCMAKE_BUILD_TYPE=Release"
176                     "-DBUILD_SHARED_LIBS=ON" ".."
177                 } try-process
178                 qw{ msbuild grpc.sln /property:Configuration=Release /p:Platform=Win32 } try-process
179             ] [
180                 {
181                     "cmake"
182                     "-G" "Visual Studio 17 2022"
183                     "-DCMAKE_BUILD_TYPE=Release"
184                     "-DBUILD_SHARED_LIBS=ON" ".."
185                 } try-process
186                 qw{ msbuild grpc.sln /property:Configuration=Release } try-process
187             ] if
188             "bin/Release/libprotobuf-lite.dll" copy-output-file
189             "bin/Release/libprotobuf.dll" copy-output-file
190             "bin/Release/libprotoc.dll" copy-output-file
191             "bin/Release/abseil_dll.dll" copy-output-file
192             "bin/Release/protoc.exe" copy-output-file
193         ] with-build-directory-as
194     ] with-github-worktree-tag ;
195
196 : build-pcre-dll ( -- )
197     latest-pcre-tar-gz [
198         [
199             32-bit? [
200                 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
201                 qw{ msbuild PCRE.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
202             ] [
203                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
204                 qw{ msbuild PCRE.sln /m /property:Configuration=Release } try-process
205             ] if
206             "Release/pcre.dll" copy-output-file
207         ] with-build-directory
208     ] with-tar-gz ;
209
210 : build-pcre2-dll ( -- )
211     "PCRE2Project" "pcre2" pcre2-release-versions last [
212         [
213             32-bit? [
214                 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
215                 qw{ msbuild PCRE2.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
216             ] [
217                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
218                 qw{ msbuild PCRE2.sln /m /property:Configuration=Release } try-process
219             ] if
220             { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
221         ] with-build-directory
222     ] with-github-worktree-tag ;
223
224 ! choco install -y meson winflexbison3
225 : build-postgres-dll ( -- )
226     "postgres" "postgres" postgres-release-versions last [
227         "src/tools/msvc/clean.bat" prepend-current-path try-process
228         qw{ meson setup build } try-process
229         "build" prepend-current-path
230         [ { "ninja" } try-process ] with-directory
231         "build/src/interfaces/libpq/libpq.dll" copy-output-file
232     ] with-github-worktree-tag ;
233
234 ! choco install -y glfw3
235 : build-raylib-dll ( -- )
236     "raysan5" "raylib" raylib-release-versions last [
237         [
238             32-bit? [
239                 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
240                 qw{ msbuild raylib.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
241             ] [
242                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
243                 qw{ msbuild raylib.sln /m /property:Configuration=Release } try-process
244             ] if
245             "raylib/Release/raylib.dll" copy-output-file
246         ] with-build-directory
247     ] with-github-worktree-tag ;
248
249 :: build-raygui-dll ( -- )
250     "raysan5" "raygui" raygui-release-versions last [
251         "raysan5" "raylib" raylib-versions last github-tag-disk-checkout-path :> $raylib-dir
252         $raylib-dir "src" append-path :> $raylib-src
253         $raylib-dir "build/raylib/Release/raylib.lib" append-path :> $raylib-lib
254
255         "src/raygui.h" "src/raygui.c" copy-file
256         32-bit? [
257             [ "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
258         ] [
259             [ "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
260         ] if
261         "raygui.dll" copy-output-file
262     ] with-github-worktree-tag ;
263
264 : build-ripgrep ( -- )
265     "BurntSushi" "ripgrep" ripgrep-versions last [
266         qw{ cargo +nightly build --release --features pcre2,simd-accel } try-process
267         "target/release/rg.exe" copy-output-file
268     ] with-github-worktree-tag ;
269
270 : build-snappy-dll ( -- )
271     "google" "snappy" snappy-versions last [
272         [
273             32-bit? [
274                 qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
275                 qw{ msbuild Snappy.sln /m /property:Configuration=Release /p:Platform=Win32 } try-process
276             ] [
277                 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
278                 qw{ msbuild Snappy.sln /m /property:Configuration=Release } try-process
279             ] if
280             "Release/snappy.dll" copy-output-file
281         ] with-build-directory
282     ] with-github-worktree-tag ;
283
284 : build-sqlite-dll ( -- )
285     "sqlite" "sqlite" sqlite-versions last [
286         qw{ nmake /f Makefile.msc clean } try-process
287         qw{ nmake /f Makefile.msc } try-process
288         "sqlite3.dll" copy-output-file
289     ] with-github-worktree-tag ;
290
291 : build-duckdb-dll ( -- )
292     "duckdb" "duckdb" duckdb-versions last [
293         [
294             32-bit? [
295                 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
296                 qw{ msbuild duckdb.sln /property:Configuration=Release /p:Platform=Win32 } try-process
297             ] [
298                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
299                 qw{ msbuild duckdb.sln /property:Configuration=Release } try-process
300             ] if
301             "src/Release/duckdb.dll" copy-output-file
302             "Release/duckdb.exe" copy-output-file
303         ] with-build-directory
304     ] with-github-worktree-tag ;
305
306 : build-yaml-dll ( -- )
307     "yaml" "libyaml" yaml-versions last [
308         [
309             32-bit? [
310                 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
311                 qw{ msbuild yaml.sln /property:Configuration=Release /p:Platform=Win32 } try-process
312             ] [
313                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
314                 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
315             ] if
316
317             "Release/yaml.dll" copy-output-file
318         ] with-build-directory
319     ] with-github-worktree-tag ;
320
321 : build-zeromq-dll ( -- )
322     "zeromq" "libzmq" zeromq-versions last [
323         [
324             32-bit? [
325                 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
326                 qw{ msbuild ZeroMQ.sln /property:Configuration=Release /p:Platform=Win32 } try-process
327             ] [
328                 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
329                 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
330             ] if
331             "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
332         ] with-build-directory
333     ] with-github-worktree-tag ;
334
335 : build-zlib-dll ( -- )
336     "madler" "zlib" zlib-versions last [
337         qw{ nmake /f win32/Makefile.msc clean } try-process
338         qw{ nmake /f win32/Makefile.msc } try-process
339         "zlib1.dll" copy-output-file
340     ] with-github-worktree-tag ;
341
342 : build-lz4 ( -- )
343     "lz4" "lz4" lz4-versions last [
344         "build/cmake" [
345             [
346                 32-bit? [
347                     qw{ cmake -A Win32 -DBUILD_SHARED_LIBS=ON .. } try-process
348                     qw{ msbuild LZ4.sln /property:Configuration=Release /p:Platform=Win32 } try-process
349                 ] [
350                     qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
351                     qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
352                 ] if
353                 "Release/lz4.dll" copy-output-file
354             ] with-build-directory
355         ] with-directory
356     ] with-github-worktree-tag ;
357
358 : build-zstd-dll ( -- )
359     "facebook" "zstd" zstd-versions last [
360         32-bit? [
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                 -Dlzma=disabled
372                 -Dzlib=disabled
373                 build/meson builddir
374             } try-process
375         ] [
376             qw{
377                 meson setup
378                 --buildtype=debugoptimized
379                 -Db_lundef=false
380                 -Dauto_features=enabled
381                 -Dbin_programs=true
382                 -Dbin_tests=true
383                 -Dbin_contrib=true
384                 -Ddefault_library=both
385                 -Dlz4=disabled
386                 build/meson builddir
387             } try-process
388         ] if
389         "builddir" prepend-current-path
390         [
391             { "ninja" } try-process
392             "lib/zstd-1.dll" copy-output-file
393         ] with-directory
394     ] with-github-worktree-tag ;
395
396 ! Probably not needed on Windows 10+
397 : install-windows-redistributable ( -- )
398     [
399         "https://aka.ms/vs/17/release/vc_redist.x64.exe" download
400         qw{ vc_redist.x64.exe /install /passive /norestart } try-process
401     ] with-temp-directory ;
402
403 : build-windows-dlls ( -- )
404     dll-out-directory make-directories
405     build-winflexbison
406     build-openssl-dlls
407     build-blas
408     build-lz4
409     build-openal-dll
410     build-pcre2-dll
411     32-bit? [ build-postgres-dll ] unless
412     build-raylib-dll
413     build-raygui-dll
414     build-snappy-dll
415     build-sqlite-dll
416     build-yaml-dll
417     build-zeromq-dll
418     build-zlib-dll
419     build-zstd-dll
420     build-cairo-dll
421     build-libressl-dlls
422     build-fftw-dll
423     build-pcre-dll ;
424
425 : build-unused-windows-dlls ( -- )
426     dll-out-directory make-directories
427     build-grpc-dll
428     rustup-update
429     build-ripgrep
430     build-duckdb-dll ;