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
8 ! choco install -y meson StrawberryPerl nasm winflexbison3 glfw3 jom
9 ! jom is for building openssl in parallel
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 ;
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 ;
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 ;
26 : build-fftw-dll ( -- )
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
33 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
34 qw{ msbuild fftw.sln /m /property:Configuration=Release } try-process
36 "Release/fftw3.dll" copy-output-file
37 ] with-build-directory
40 : build-winflexbison ( -- )
41 "lexxmark" "winflexbison" winflexbison-versions last [
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 ;
51 "xianyi" "OpenBLAS" blas-versions last [
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
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
60 "lib/RELEASE/openblas.dll" "blas.dll" copy-output-file-as
61 ] with-build-directory
62 ] with-github-worktree-tag ;
64 : build-capnproto-dll ( -- )
65 "capnproto" "capnproto" capnproto-versions last [
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
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
74 ! "raylib/Release/raylib.dll" copy-output-file
75 ] with-build-directory
76 ] with-github-worktree-tag ;
79 : build-openssl-32-dlls ( -- )
80 "openssl" "openssl" openssl-release-versions last [
82 "ProgramW6432" os-env program-files or
83 "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
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 ;
91 : build-openssl-64-dlls ( -- )
92 "openssl" "openssl" openssl-release-versions last [
94 program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
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 ;
102 : build-openssl-dlls ( -- )
103 32-bit? [ build-openssl-32-dlls ] [ build-openssl-64-dlls ] if ;
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
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"
119 } delete-output-files
120 ] with-gitlab-worktree-tag ;
122 : build-libressl-dlls ( -- )
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
129 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
130 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
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
138 : build-openal-dll ( -- )
139 "kcat" "openal-soft" openal-versions last [
144 "-G" "Visual Studio 17 2022"
146 "-DCMAKE_BUILD_TYPE=Release"
147 "-DBUILD_SHARED_LIBS=ON" ".."
149 qw{ msbuild OpenAL.sln /property:Configuration=Release /p:Platform=Win32 } try-process
153 "-G" "Visual Studio 17 2022"
154 "-DCMAKE_BUILD_TYPE=Release"
155 "-DBUILD_SHARED_LIBS=ON" ".."
157 qw{ msbuild OpenAL.sln /property:Configuration=Release } try-process
159 "Release/OpenAL32.dll" copy-output-file
160 ] with-build-directory
161 ] with-github-worktree-tag ;
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
173 "-G" "Visual Studio 17 2022"
175 "-DCMAKE_BUILD_TYPE=Release"
176 "-DBUILD_SHARED_LIBS=ON" ".."
178 qw{ msbuild grpc.sln /property:Configuration=Release /p:Platform=Win32 } try-process
182 "-G" "Visual Studio 17 2022"
183 "-DCMAKE_BUILD_TYPE=Release"
184 "-DBUILD_SHARED_LIBS=ON" ".."
186 qw{ msbuild grpc.sln /property:Configuration=Release } try-process
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 ;
196 : build-pcre-dll ( -- )
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
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
206 "Release/pcre.dll" copy-output-file
207 ] with-build-directory
210 : build-pcre2-dll ( -- )
211 "PCRE2Project" "pcre2" pcre2-release-versions last [
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
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
220 { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
221 ] with-build-directory
222 ] with-github-worktree-tag ;
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 ;
234 ! choco install -y glfw3
235 : build-raylib-dll ( -- )
236 "raysan5" "raylib" raylib-release-versions last [
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
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
245 "raylib/Release/raylib.dll" copy-output-file
246 ] with-build-directory
247 ] with-github-worktree-tag ;
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
255 "src/raygui.h" "src/raygui.c" copy-file
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
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
261 "raygui.dll" copy-output-file
262 ] with-github-worktree-tag ;
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 ;
270 : build-snappy-dll ( -- )
271 "google" "snappy" snappy-versions last [
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
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
280 "Release/snappy.dll" copy-output-file
281 ] with-build-directory
282 ] with-github-worktree-tag ;
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 ;
291 : build-duckdb-dll ( -- )
292 "duckdb" "duckdb" duckdb-versions last [
295 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
296 qw{ msbuild duckdb.sln /property:Configuration=Release /p:Platform=Win32 } try-process
298 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
299 qw{ msbuild duckdb.sln /property:Configuration=Release } try-process
301 "src/Release/duckdb.dll" copy-output-file
302 "Release/duckdb.exe" copy-output-file
303 ] with-build-directory
304 ] with-github-worktree-tag ;
306 : build-yaml-dll ( -- )
307 "yaml" "libyaml" yaml-versions last [
310 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
311 qw{ msbuild yaml.sln /property:Configuration=Release /p:Platform=Win32 } try-process
313 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
314 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
317 "Release/yaml.dll" copy-output-file
318 ] with-build-directory
319 ] with-github-worktree-tag ;
321 : build-zeromq-dll ( -- )
322 "zeromq" "libzmq" zeromq-versions last [
325 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
326 qw{ msbuild ZeroMQ.sln /property:Configuration=Release /p:Platform=Win32 } try-process
328 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
329 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
331 "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
332 ] with-build-directory
333 ] with-github-worktree-tag ;
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 ;
343 "lz4" "lz4" lz4-versions last [
347 qw{ cmake -A Win32 -DBUILD_SHARED_LIBS=ON .. } try-process
348 qw{ msbuild LZ4.sln /property:Configuration=Release /p:Platform=Win32 } try-process
350 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
351 qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
353 "Release/lz4.dll" copy-output-file
354 ] with-build-directory
356 ] with-github-worktree-tag ;
358 : build-zstd-dll ( -- )
359 "facebook" "zstd" zstd-versions last [
363 --buildtype=debugoptimized
365 -Dauto_features=enabled
369 -Ddefault_library=both
378 --buildtype=debugoptimized
380 -Dauto_features=enabled
384 -Ddefault_library=both
389 "builddir" prepend-current-path
391 { "ninja" } try-process
392 "lib/zstd-1.dll" copy-output-file
394 ] with-github-worktree-tag ;
396 ! Probably not needed on Windows 10+
397 : install-windows-redistributable ( -- )
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 ;
403 : build-windows-dlls ( -- )
404 dll-out-directory make-directories
411 32-bit? [ build-postgres-dll ] unless
425 : build-unused-windows-dlls ( -- )
426 dll-out-directory make-directories