1 ! Copyright (C) 2023 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors build-from-source environment html.parser
4 html.parser.analyzer http.client io.backend io.directories
5 io.encodings.utf8 io.files io.files.temp io.launcher
6 io.pathnames kernel multiline qw sequences sorting.human
7 sorting.slots windows.shell32 ;
8 IN: build-from-source.windows
10 ! choco install -y meson StrawberryPerl nasm winflexbison3 glfw3
12 ! From `choco install -y nasm`
13 ! Add nasm to path (windows+r sysdm.cpl -> Advanced tab -> Environment Variables -> New -> "c:\Program Files\NASM")
14 : check-nasm ( -- ) { "nasm.exe" "-h" } try-process ;
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 : latest-fftw ( -- path )
27 "https://ftp.fftw.org/pub/fftw/" [
29 parse-html find-links concat
30 [ name>> text = ] filter
32 [ "fftw-" head? ] filter
33 [ ".tar.gz" tail? ] filter
37 : build-fftw-dll ( -- )
40 { "cmake" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
41 { "msbuild" "fftw.sln" "/m" "/property:Configuration=Release" } try-process
42 "Release/fftw3.dll" copy-output-file
43 ] with-build-directory
46 : build-winflexbison ( -- )
47 "https://github.com/lexxmark/winflexbison.git" [
49 { "cmake" ".." } try-process
50 { "cmake" "--build" "." "--config" "Release" "--target" "package" } try-process
51 ] with-build-directory
52 "bin/Release/win_bison.exe" "bison.exe" copy-vm-file-as
53 "bin/Release/win_flex.exe" "flex.exe" copy-vm-file-as
54 ] with-updated-git-repo ;
56 : build-openssl-64-dlls ( -- )
57 "https://github.com/openssl/openssl.git" [
59 program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
62 { "perl" "Configure" "-DOPENSSL_PIC" "VC-WIN64A" } try-process ! "VC-WIN32"
63 { "nmake" } try-process
64 { "apps/libssl-3-x64.dll" "apps/libcrypto-3-x64.dll" } copy-output-files
65 "apps/libssl-3-x64.dll" "libssl-38.dll" copy-output-file-as
66 "apps/libcrypto-3-x64.dll" "libcrypto-37.dll" copy-output-file-as
67 ] with-updated-git-repo ;
69 : build-cairo-dll ( -- )
70 "https://github.com/freedesktop/cairo.git" [
71 qw{ meson setup build2 } try-process
72 "build2" prepend-current-path
73 [ { "ninja" } try-process ] with-directory
74 "." find-dlls copy-output-files
76 "gdbus-example-objectmanager.dll"
77 "moduletestplugin_a_library.dll"
78 "moduletestplugin_a_plugin.dll"
79 "moduletestplugin_b_library.dll"
80 "moduletestplugin_b_plugin.dll"
84 ] with-updated-git-repo ;
86 : latest-libressl ( -- path )
87 "https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/" [
88 http-get nip parse-html find-links concat
89 [ name>> text = ] filter
91 [ "libressl-" head? ] filter
92 [ ".tar.gz" tail? ] filter last
95 : build-libressl-dlls ( -- )
98 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
99 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
101 "crypto/Release/crypto-50.dll"
102 "ssl/Release/ssl-53.dll"
103 "tls/Release/tls-26.dll"
105 ] with-build-directory
108 : latest-pcre-tar-gz ( -- path )
109 "https://ftp.exim.org/pub/pcre/" [
110 http-get nip parse-html find-links concat
111 [ name>> text = ] filter [ text>> ] map
112 [ "pcre-" head? ] filter
113 [ ".tar.gz" tail? ] filter last
116 : build-pcre-dll ( -- )
119 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
120 qw{ msbuild PCRE.sln /m /property:Configuration=Release } try-process
121 "Release/pcre.dll" copy-output-file
122 ] with-build-directory
125 : build-pcre2-dll ( -- )
126 "https://github.com/PCRE2Project/pcre2.git" [
128 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
129 qw{ msbuild PCRE2.sln /m /property:Configuration=Release } try-process
130 { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
131 ] with-build-directory
132 ] with-updated-git-repo ;
134 ! choco install -y meson winflexbison3
135 : build-postgres-dll ( -- )
136 "https://github.com/postgres/postgres" [
137 "src/tools/msvc/clean.bat" prepend-current-path try-process
138 qw{ meson setup build2 } try-process
139 "build2" prepend-current-path
140 [ { "ninja" } try-process ] with-directory
141 "build2/src/interfaces/libpq/libpq.dll" copy-output-file
142 ] with-updated-git-repo ;
144 ! choco install -y glfw3
145 : build-raylib-dll ( -- )
146 "https://github.com/raysan5/raylib.git" [
148 { "cmake" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" "-DBUILD_EXAMPLES=OFF" "-DUSE_EXTERNAL_GLFW=OFF" ".." } try-process
149 { "msbuild" "raylib.sln" "/m" "/property:Configuration=Release" } try-process
150 "raylib/Release/raylib.dll" copy-output-file
151 ] with-build-directory
152 ] with-updated-git-repo ;
154 : build-raygui-dll ( -- )
155 "https://github.com/raysan5/raygui.git" [
156 "src/raygui.h" "src/raygui.c" copy-file
157 qw{ cl /O2 /I ../raylib/src/ /D_USRDLL /D_WINDLL /DRAYGUI_IMPLEMENTATION /DBUILD_LIBTYPE_SHARED src/raygui.c /LD /Feraygui.dll /link /LIBPATH ../raylib/build/raylib/Release/raylib.lib /subsystem:windows /machine:x64 } try-process
158 "raygui.dll" copy-output-file
159 ] with-updated-git-repo ;
161 : build-snappy-dll ( -- )
162 "https://github.com/google/snappy.git" [
164 { "cmake" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" "-DSNAPPY_BUILD_TESTS=OFF" "-DSNAPPY_BUILD_BENCHMARKS=OFF" ".." } try-process
165 { "msbuild" "Snappy.sln" "/m" "/property:Configuration=Release" } try-process
166 "Release/snappy.dll" copy-output-file
167 ] with-build-directory
168 ] with-updated-git-repo ;
170 : build-sqlite3-dll ( -- )
171 "https://github.com/sqlite/sqlite.git" [
172 { "nmake" "/f" "Makefile.msc" "clean" } try-process
173 { "nmake" "/f" "Makefile.msc" } try-process
174 "sqlite3.dll" copy-output-file
175 ] with-updated-git-repo ;
177 : build-yaml-dll ( -- )
178 "https://github.com/yaml/libyaml.git" [
180 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
181 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
183 "Release/yaml.dll" copy-output-file
184 ] with-build-directory
185 ] with-updated-git-repo ;
187 : build-zeromq-dll ( -- )
188 "https://github.com/zeromq/libzmq.git" [
190 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
191 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
192 "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
193 ] with-build-directory
194 ] with-updated-git-repo ;
196 : build-zlib-dll ( -- )
197 "https://github.com/madler/zlib" [
198 { "nmake" "/f" "win32/Makefile.msc" "clean" } try-process
199 { "nmake" "/f" "win32/Makefile.msc" } try-process
200 "zlib1.dll" copy-output-file
201 ] with-updated-git-repo ;
204 "https://github.com/lz4/lz4.git" [
207 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
208 qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
209 "Release/lz4.dll" copy-output-file
210 ] with-build-directory
212 ] with-updated-git-repo ;
214 : build-zstd-dll ( -- )
215 "https://github.com/facebook/zstd.git" [
218 --buildtype=debugoptimized
220 -Dauto_features=enabled
224 -Ddefault_library=both
228 "builddir" prepend-current-path
230 { "ninja" } try-process
231 "lib/zstd-1.dll" copy-output-file
233 ] with-updated-git-repo ;
235 ! Probably not needed on Windows 10+
236 : install-windows-redistributable ( -- )
238 "https://aka.ms/vs/17/release/vc_redist.x64.exe" download
239 qw{ vc_redist.x64.exe /install /passive /norestart } try-process
240 ] with-temp-directory ;
242 : build-windows-dlls ( -- )
243 dll-out-directory make-directories
245 build-openssl-64-dlls