]> gitweb.factorcode.org Git - factor.git/blob - extra/build-from-source/windows/windows.factor
Switch to https urls
[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 sorting.slots 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-by 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     ] with-updated-git-repo ;
66
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
71         [ text>> ] map
72         [ "libressl-" head? ] filter
73         [ ".tar.gz" tail? ] filter last
74     ] keep prepend ;
75
76 : build-libressl-dlls ( -- )
77     latest-libressl [
78         [
79             qw{ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. } try-process
80             qw{ msbuild LibreSSL.sln /m /property:Configuration=Release } try-process
81             {
82                 "crypto/Release/crypto-50.dll"
83                 "ssl/Release/ssl-53.dll"
84                 "tls/Release/tls-26.dll"
85             } copy-output-files
86         ] with-build-directory
87     ] with-tar-gz ;
88
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
95     ] keep prepend ;
96
97 : build-pcre-dll ( -- )
98     latest-pcre-tar-gz [
99         [
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
104     ] with-tar-gz ;
105
106 : build-pcre2-dll ( -- )
107     "https://github.com/PCRE2Project/pcre2.git" [
108         [
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 ;
114
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 ;
124
125 ! choco install -y glfw3
126 : build-raylib-dll ( -- )
127     "https://github.com/raysan5/raylib.git" [
128         [
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 ;
134
135 : build-snappy-dll ( -- )
136     "https://github.com/google/snappy.git" [
137         [
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 ;
143
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 ;
150
151 : build-yaml-dll ( -- )
152     "https://github.com/yaml/libyaml.git" [
153         [
154             qw{ cmake -DBUILD_SHARED_LIBS=ON .. } try-process
155             qw{ msbuild yaml.sln /property:Configuration=Release } try-process
156
157             "Release/yaml.dll" copy-output-file
158         ] with-build-directory
159     ] with-updated-git-repo ;
160
161 : build-zeromq-dll ( -- )
162     "https://github.com/zeromq/libzmq.git" [
163         [
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 ;
169
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 ;
176
177 : build-lz4 ( -- )
178     "https://github.com/lz4/lz4.git" [
179         "build/cmake" [
180             [
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
185         ] with-directory
186     ] with-updated-git-repo ;
187
188 : build-zstd-dll ( -- )
189     "https://github.com/facebook/zstd.git" [
190         qw{
191             meson setup
192             --buildtype=debugoptimized
193             -Db_lundef=false
194             -Dauto_features=enabled
195             -Dbin_programs=true
196             -Dbin_tests=true
197             -Dbin_contrib=true
198             -Ddefault_library=both
199             -Dlz4=disabled
200             build/meson builddir
201         } try-process
202         "builddir" prepend-current-path
203         [
204             { "ninja" } try-process
205             "lib/zstd-1.dll" "libzstd.dll" copy-output-file-as
206         ] with-directory
207     ] with-updated-git-repo ;
208
209 ! Probably not needed on Windows 10+
210 : install-windows-redistributable ( -- )
211     [
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 ;
215
216 : build-windows-dlls ( -- )
217     dll-out-directory make-directories
218     build-openssl-64-dlls
219     build-libressl-dlls
220     build-fftw-dll
221     build-pcre-dll
222     build-pcre2-dll
223     build-postgres-dll
224     build-raylib-dll
225     build-snappy-dll
226     build-sqlite3-dll
227     build-yaml-dll
228     build-zeromq-dll
229     build-zlib-dll
230     build-zstd-dll ;