]> gitweb.factorcode.org Git - factor.git/blob - extra/build-from-source/windows/windows.factor
Rename and add sorting words
[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: 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 windows.shell32 ;
8 IN: build-from-source.windows
9
10 ! choco install -y meson StrawberryPerl nasm winflexbison3 glfw3
11
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 ;
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 : latest-fftw ( -- path )
27     "https://ftp.fftw.org/pub/fftw/" [
28         http-get nip
29         parse-html find-links concat
30         [ name>> text = ] filter
31         [ text>> ] map
32         [ "fftw-" head? ] filter
33         [ ".tar.gz" tail? ] filter
34         human-sort last
35     ] keep prepend-path ;
36
37 : build-fftw-dll ( -- )
38     latest-fftw [
39         [
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
44     ] with-tar-gz ;
45
46 : build-winflexbison ( -- )
47     "https://github.com/lexxmark/winflexbison.git" [
48         [
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 ;
55
56 : build-openssl-64-dlls ( -- )
57     "https://github.com/openssl/openssl.git" [
58         check-perl
59         program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
60         check-nasm
61         check-nmake
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 ;
68
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
75         {
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"
81             "testmodulea.dll"
82             "testmoduleb.dll"
83         } delete-output-files
84     ] with-updated-git-repo ;
85
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
90         [ text>> ] map
91         [ "libressl-" head? ] filter
92         [ ".tar.gz" tail? ] filter last
93     ] keep prepend ;
94
95 : build-libressl-dlls ( -- )
96     latest-libressl [
97         [
98             qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
99             qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
100             {
101                 "crypto/Release/crypto-50.dll"
102                 "ssl/Release/ssl-53.dll"
103                 "tls/Release/tls-26.dll"
104             } copy-output-files
105         ] with-build-directory
106     ] with-tar-gz ;
107
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
114     ] keep prepend ;
115
116 : build-pcre-dll ( -- )
117     latest-pcre-tar-gz [
118         [
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
123     ] with-tar-gz ;
124
125 : build-pcre2-dll ( -- )
126     "https://github.com/PCRE2Project/pcre2.git" [
127         [
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 ;
133
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 ;
143
144 ! choco install -y glfw3
145 : build-raylib-dll ( -- )
146     "https://github.com/raysan5/raylib.git" [
147         [
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 ;
153
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 ;
160
161 : build-snappy-dll ( -- )
162     "https://github.com/google/snappy.git" [
163         [
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 ;
169
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 ;
176
177 : build-yaml-dll ( -- )
178     "https://github.com/yaml/libyaml.git" [
179         [
180             qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
181             qw{ msbuild yaml.sln /property:Configuration=Release } try-process
182
183             "Release/yaml.dll" copy-output-file
184         ] with-build-directory
185     ] with-updated-git-repo ;
186
187 : build-zeromq-dll ( -- )
188     "https://github.com/zeromq/libzmq.git" [
189         [
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 ;
195
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 ;
202
203 : build-lz4 ( -- )
204     "https://github.com/lz4/lz4.git" [
205         "build/cmake" [
206             [
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
211         ] with-directory
212     ] with-updated-git-repo ;
213
214 : build-zstd-dll ( -- )
215     "https://github.com/facebook/zstd.git" [
216         qw{
217             meson setup
218             --buildtype=debugoptimized
219             -Db_lundef=false
220             -Dauto_features=enabled
221             -Dbin_programs=true
222             -Dbin_tests=true
223             -Dbin_contrib=true
224             -Ddefault_library=both
225             -Dlz4=disabled
226             build/meson builddir
227         } try-process
228         "builddir" prepend-current-path
229         [
230             { "ninja" } try-process
231             "lib/zstd-1.dll" copy-output-file
232         ] with-directory
233     ] with-updated-git-repo ;
234
235 ! Probably not needed on Windows 10+
236 : install-windows-redistributable ( -- )
237     [
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 ;
241
242 : build-windows-dlls ( -- )
243     dll-out-directory make-directories
244     build-cairo-dll
245     build-openssl-64-dlls
246     build-libressl-dlls
247     build-fftw-dll
248     build-pcre-dll
249     build-pcre2-dll
250     build-postgres-dll
251     build-raylib-dll
252     build-snappy-dll
253     build-sqlite3-dll
254     build-yaml-dll
255     build-zeromq-dll
256     build-zlib-dll
257     build-zstd-dll ;