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-openssl-32-dlls ( -- )
65 "openssl" "openssl" openssl-versions last [
67 "ProgramW6432" os-env program-files or
68 "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
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 ;
76 : build-openssl-64-dlls ( -- )
77 "openssl" "openssl" openssl-versions last [
79 program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
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 ;
87 : build-openssl-dlls ( -- )
88 32-bit? [ build-openssl-32-dlls ] [ build-openssl-64-dlls ] if ;
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
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"
104 } delete-output-files
105 ] with-gitlab-worktree-tag ;
107 : build-libressl-dlls ( -- )
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
114 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
115 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
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
123 : build-openal-dll ( -- )
124 "kcat" "openal-soft" openal-versions last [
129 "-G" "Visual Studio 17 2022"
131 "-DCMAKE_BUILD_TYPE=Release"
132 "-DBUILD_SHARED_LIBS=ON" ".."
134 qw{ msbuild OpenAL.sln /property:Configuration=Release /p:Platform=Win32 } try-process
138 "-G" "Visual Studio 17 2022"
139 "-DCMAKE_BUILD_TYPE=Release"
140 "-DBUILD_SHARED_LIBS=ON" ".."
142 qw{ msbuild OpenAL.sln /property:Configuration=Release } try-process
144 "Release/OpenAL32.dll" copy-output-file
145 ] with-build-directory
146 ] with-github-worktree-tag ;
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
158 "-G" "Visual Studio 17 2022"
160 "-DCMAKE_BUILD_TYPE=Release"
161 "-DBUILD_SHARED_LIBS=ON" ".."
163 qw{ msbuild grpc.sln /property:Configuration=Release /p:Platform=Win32 } try-process
167 "-G" "Visual Studio 17 2022"
168 "-DCMAKE_BUILD_TYPE=Release"
169 "-DBUILD_SHARED_LIBS=ON" ".."
171 qw{ msbuild grpc.sln /property:Configuration=Release } try-process
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 ;
181 : build-pcre-dll ( -- )
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
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
191 "Release/pcre.dll" copy-output-file
192 ] with-build-directory
195 : build-pcre2-dll ( -- )
196 "PCRE2Project" "pcre2" pcre2-versions last [
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
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
205 { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
206 ] with-build-directory
207 ] with-github-worktree-tag ;
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 ;
219 ! choco install -y glfw3
220 : build-raylib-dll ( -- )
221 "raysan5" "raylib" raylib-versions last [
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
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
230 "raylib/Release/raylib.dll" copy-output-file
231 ] with-build-directory
232 ] with-github-worktree-tag ;
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
240 "src/raygui.h" "src/raygui.c" copy-file
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
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
246 "raygui.dll" copy-output-file
247 ] with-github-worktree-tag ;
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 ;
255 : build-snappy-dll ( -- )
256 "google" "snappy" snappy-versions last [
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
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
265 "Release/snappy.dll" copy-output-file
266 ] with-build-directory
267 ] with-github-worktree-tag ;
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 ;
276 : build-duckdb-dll ( -- )
277 "duckdb" "duckdb" duckdb-versions last [
280 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
281 qw{ msbuild duckdb.sln /property:Configuration=Release /p:Platform=Win32 } try-process
283 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
284 qw{ msbuild duckdb.sln /property:Configuration=Release } try-process
286 "src/Release/duckdb.dll" copy-output-file
287 "Release/duckdb.exe" copy-output-file
288 ] with-build-directory
289 ] with-github-worktree-tag ;
291 : build-yaml-dll ( -- )
292 "yaml" "libyaml" yaml-versions last [
295 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
296 qw{ msbuild yaml.sln /property:Configuration=Release /p:Platform=Win32 } try-process
298 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
299 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
302 "Release/yaml.dll" copy-output-file
303 ] with-build-directory
304 ] with-github-worktree-tag ;
306 : build-zeromq-dll ( -- )
307 "zeromq" "libzmq" zeromq-versions last [
310 qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
311 qw{ msbuild ZeroMQ.sln /property:Configuration=Release /p:Platform=Win32 } try-process
313 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
314 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
316 "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
317 ] with-build-directory
318 ] with-github-worktree-tag ;
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 ;
328 "lz4" "lz4" lz4-versions last [
332 qw{ cmake -A Win32 -DBUILD_SHARED_LIBS=ON .. } try-process
333 qw{ msbuild LZ4.sln /property:Configuration=Release /p:Platform=Win32 } try-process
335 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
336 qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
338 "Release/lz4.dll" copy-output-file
339 ] with-build-directory
341 ] with-github-worktree-tag ;
343 : build-zstd-dll ( -- )
344 "facebook" "zstd" zstd-versions last [
348 --buildtype=debugoptimized
350 -Dauto_features=enabled
354 -Ddefault_library=both
363 --buildtype=debugoptimized
365 -Dauto_features=enabled
369 -Ddefault_library=both
374 "builddir" prepend-current-path
376 { "ninja" } try-process
377 "lib/zstd-1.dll" copy-output-file
379 ] with-github-worktree-tag ;
381 ! Probably not needed on Windows 10+
382 : install-windows-redistributable ( -- )
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 ;
388 : build-windows-dlls ( -- )
389 dll-out-directory make-directories
396 32-bit? [ build-postgres-dll ] unless
410 : build-unused-windows-dlls ( -- )
411 dll-out-directory make-directories