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
34 { human<=> } sort-by last
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 ] with-updated-git-repo ;
67 : latest-libressl ( -- path )
68 "https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/" [
69 http-get nip parse-html find-links concat
70 [ name>> text = ] filter
72 [ "libressl-" head? ] filter
73 [ ".tar.gz" tail? ] filter last
76 : build-libressl-dlls ( -- )
79 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
80 qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
82 "crypto/Release/crypto-50.dll"
83 "ssl/Release/ssl-53.dll"
84 "tls/Release/tls-26.dll"
86 ] with-build-directory
89 : latest-pcre-tar-gz ( -- path )
90 "https://ftp.exim.org/pub/pcre/" [
91 http-get nip parse-html find-links concat
92 [ name>> text = ] filter [ text>> ] map
93 [ "pcre-" head? ] filter
94 [ ".tar.gz" tail? ] filter last
97 : build-pcre-dll ( -- )
100 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
101 qw{ msbuild PCRE.sln /m /property:Configuration=Release } try-process
102 "Release/pcre.dll" copy-output-file
103 ] with-build-directory
106 : build-pcre2-dll ( -- )
107 "https://github.com/PCRE2Project/pcre2.git" [
109 qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON .. } try-process
110 qw{ msbuild PCRE2.sln /m /property:Configuration=Release } try-process
111 { "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
112 ] with-build-directory
113 ] with-updated-git-repo ;
115 ! choco install -y meson winflexbison3
116 : build-postgres-dll ( -- )
117 "https://github.com/postgres/postgres" [
118 "src/tools/msvc/clean.bat" prepend-current-path try-process
119 qw{ meson setup build2 } try-process
120 "build2" prepend-current-path
121 [ { "ninja" } try-process ] with-directory
122 "build2/src/interfaces/libpq/libpq.dll" copy-output-file
123 ] with-updated-git-repo ;
125 ! choco install -y glfw3
126 : build-raylib-dll ( -- )
127 "https://github.com/raysan5/raylib.git" [
129 { "cmake" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" "-DBUILD_EXAMPLES=OFF" "-DUSE_EXTERNAL_GLFW=OFF" ".." } try-process
130 { "msbuild" "raylib.sln" "/m" "/property:Configuration=Release" } try-process
131 "raylib/Release/raylib.dll" copy-output-file
132 ] with-build-directory
133 ] with-updated-git-repo ;
135 : build-snappy-dll ( -- )
136 "https://github.com/google/snappy.git" [
138 { "cmake" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" "-DSNAPPY_BUILD_TESTS=OFF" "-DSNAPPY_BUILD_BENCHMARKS=OFF" ".." } try-process
139 { "msbuild" "Snappy.sln" "/m" "/property:Configuration=Release" } try-process
140 "Release/snappy.dll" copy-output-file
141 ] with-build-directory
142 ] with-updated-git-repo ;
144 : build-sqlite3-dll ( -- )
145 "https://github.com/sqlite/sqlite.git" [
146 { "nmake" "/f" "Makefile.msc" "clean" } try-process
147 { "nmake" "/f" "Makefile.msc" } try-process
148 "sqlite3.dll" copy-output-file
149 ] with-updated-git-repo ;
151 : build-yaml-dll ( -- )
152 "https://github.com/yaml/libyaml.git" [
154 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
155 qw{ msbuild yaml.sln /property:Configuration=Release } try-process
157 "Release/yaml.dll" copy-output-file
158 ] with-build-directory
159 ] with-updated-git-repo ;
161 : build-zeromq-dll ( -- )
162 "https://github.com/zeromq/libzmq.git" [
164 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
165 qw{ msbuild ZeroMQ.sln /property:Configuration=Release } try-process
166 "bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
167 ] with-build-directory
168 ] with-updated-git-repo ;
170 : build-zlib-dll ( -- )
171 "https://github.com/madler/zlib" [
172 { "nmake" "/f" "win32/Makefile.msc" "clean" } try-process
173 { "nmake" "/f" "win32/Makefile.msc" } try-process
174 "zlib1.dll" copy-output-file
175 ] with-updated-git-repo ;
178 "https://github.com/lz4/lz4.git" [
181 qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
182 qw{ msbuild LZ4.sln /property:Configuration=Release } try-process
183 "Release/lz4.dll" copy-output-file
184 ] with-build-directory
186 ] with-updated-git-repo ;
188 : build-zstd-dll ( -- )
189 "https://github.com/facebook/zstd.git" [
192 --buildtype=debugoptimized
194 -Dauto_features=enabled
198 -Ddefault_library=both
202 "builddir" prepend-current-path
204 { "ninja" } try-process
205 "lib/zstd-1.dll" "libzstd.dll" copy-output-file-as
207 ] with-updated-git-repo ;
209 ! Probably not needed on Windows 10+
210 : install-windows-redistributable ( -- )
212 "https://aka.ms/vs/17/release/vc_redist.x64.exe" download
213 qw{ vc_redist.x64.exe /install /passive /norestart } try-process
214 ] with-temp-directory ;
216 : build-windows-dlls ( -- )
217 dll-out-directory make-directories
218 build-openssl-64-dlls