xref: /aosp_15_r20/external/libwebsockets/READMEs/README.build-windows.md (revision 1c60b9aca93fdbc9b5f19b2d2194c91294b22281)
1*1c60b9acSAndroid Build Coastguard Worker# Some notes for the windows jungle
2*1c60b9acSAndroid Build Coastguard Worker
3*1c60b9acSAndroid Build Coastguard WorkerThis was how I compiled libwebsockets starting from a blank windows install
4*1c60b9acSAndroid Build Coastguard Workerin March - April 2020.  Doing this on a linux distro is way simpler and quicker
5*1c60b9acSAndroid Build Coastguard Workerthan all this!
6*1c60b9acSAndroid Build Coastguard Worker
7*1c60b9acSAndroid Build Coastguard Worker## Notes on vm installation
8*1c60b9acSAndroid Build Coastguard Worker
9*1c60b9acSAndroid Build Coastguard Worker### Disk size
10*1c60b9acSAndroid Build Coastguard Worker
11*1c60b9acSAndroid Build Coastguard WorkerFor building you'll need 40GB+ available for the guest storage.
12*1c60b9acSAndroid Build Coastguard Worker
13*1c60b9acSAndroid Build Coastguard Worker### Required: Windows product key
14*1c60b9acSAndroid Build Coastguard Worker
15*1c60b9acSAndroid Build Coastguard WorkerAssuming like me the first thing you do with a new laptop is install Linux over
16*1c60b9acSAndroid Build Coastguard Workerthe windows it came with, you can recover your 'windows tax' windows product key
17*1c60b9acSAndroid Build Coastguard Workerfrom your device typically using `sudo strings /sys/firmware/acpi/tables/MSDM`,
18*1c60b9acSAndroid Build Coastguard Workerand use that for your VM install.
19*1c60b9acSAndroid Build Coastguard Worker
20*1c60b9acSAndroid Build Coastguard Worker### Required: Spice guest
21*1c60b9acSAndroid Build Coastguard Worker
22*1c60b9acSAndroid Build Coastguard WorkerTo have shared clipboard, and for windows video driver to match your vm window
23*1c60b9acSAndroid Build Coastguard Workerresolution, you must install spice guest tools inside the windows VM.  It also
24*1c60b9acSAndroid Build Coastguard Workerinstalls some virtio pieces you will want.
25*1c60b9acSAndroid Build Coastguard Worker
26*1c60b9acSAndroid Build Coastguard Workerhttps://www.spice-space.org/download/windows/spice-guest-tools/spice-guest-tools-latest.exe
27*1c60b9acSAndroid Build Coastguard Worker
28*1c60b9acSAndroid Build Coastguard Worker### Blood-pressure reduction: Firefox
29*1c60b9acSAndroid Build Coastguard Worker
30*1c60b9acSAndroid Build Coastguard Workerhttps://www.mozilla.org/en-US/exp/firefox/
31*1c60b9acSAndroid Build Coastguard Worker
32*1c60b9acSAndroid Build Coastguard WorkerWhen it's up, add-ons: ublock origin, privacy badger, noscript, disable search
33*1c60b9acSAndroid Build Coastguard Workerbar prediction
34*1c60b9acSAndroid Build Coastguard Worker
35*1c60b9acSAndroid Build Coastguard Worker### Blood-pressure reduction: Clink
36*1c60b9acSAndroid Build Coastguard Worker
37*1c60b9acSAndroid Build Coastguard WorkerThis is a hack on cmd.exe that lets it understand Ctrl-R and fixup unix-style
38*1c60b9acSAndroid Build Coastguard Workerslashes automagically.
39*1c60b9acSAndroid Build Coastguard Worker
40*1c60b9acSAndroid Build Coastguard Workerhttps://github.com/mridgers/clink/releases/download/0.4.9/clink_0.4.9_setup.exe
41*1c60b9acSAndroid Build Coastguard Worker
42*1c60b9acSAndroid Build Coastguard WorkerIf you're usually using *nix, you definitely need this to keep your sanity.
43*1c60b9acSAndroid Build Coastguard Worker
44*1c60b9acSAndroid Build Coastguard Worker### Required: cmake
45*1c60b9acSAndroid Build Coastguard Worker
46*1c60b9acSAndroid Build Coastguard WorkerCMake have a windows installer thing downloadable from here
47*1c60b9acSAndroid Build Coastguard Worker
48*1c60b9acSAndroid Build Coastguard Worker[cmake](https://cmake.org/download/)
49*1c60b9acSAndroid Build Coastguard Worker
50*1c60b9acSAndroid Build Coastguard Workerafter that you can use `cmake` from the terminal OK.
51*1c60b9acSAndroid Build Coastguard Worker
52*1c60b9acSAndroid Build Coastguard Worker### Required: git
53*1c60b9acSAndroid Build Coastguard Worker
54*1c60b9acSAndroid Build Coastguard WorkerVisit the canonical git site to download their windows installer thing
55*1c60b9acSAndroid Build Coastguard Worker
56*1c60b9acSAndroid Build Coastguard Worker[git](https://git-scm.com/download/win)
57*1c60b9acSAndroid Build Coastguard Worker
58*1c60b9acSAndroid Build Coastguard Worker**Select the install option for "extra unix commands"** so you can get `ls -l`,
59*1c60b9acSAndroid Build Coastguard Worker`cp`, `mv` and suchlike working in cmd.exe... that's awesome, thanks git!
60*1c60b9acSAndroid Build Coastguard Worker
61*1c60b9acSAndroid Build Coastguard WorkerAfterwards you can just use `git` as normal from cmd.exe as well.
62*1c60b9acSAndroid Build Coastguard Worker
63*1c60b9acSAndroid Build Coastguard Worker### Required: Install the "free" "community" visual studio
64*1c60b9acSAndroid Build Coastguard Worker
65*1c60b9acSAndroid Build Coastguard WorkerYou can do this through "windows store" by searching for "visual studio"
66*1c60b9acSAndroid Build Coastguard Worker
67*1c60b9acSAndroid Build Coastguard WorkerI installed as little as possible, we just want the C "C++" tools... 7GB :-)
68*1c60b9acSAndroid Build Coastguard Worker
69*1c60b9acSAndroid Build Coastguard WorkerIt still wouldn't link without the "mt" helper tool from the
70*1c60b9acSAndroid Build Coastguard Workerhuge windows SDK, so you have to install GB of that as well.
71*1c60b9acSAndroid Build Coastguard Worker
72*1c60b9acSAndroid Build Coastguard WorkerThey don't mention it during the install, but after 30 days this "free"
73*1c60b9acSAndroid Build Coastguard Worker"community" edition demands you open a microsoft account or it stops working.
74*1c60b9acSAndroid Build Coastguard WorkerIn the install they give you the option to add a microsoft account and the
75*1c60b9acSAndroid Build Coastguard Workeralternative is, "not now, maybe later".  Compare and contrast to gcc or git or
76*1c60b9acSAndroid Build Coastguard Workerthe other FOSS projects.
77*1c60b9acSAndroid Build Coastguard Worker
78*1c60b9acSAndroid Build Coastguard Worker### Required: OpenSSL
79*1c60b9acSAndroid Build Coastguard Worker
80*1c60b9acSAndroid Build Coastguard WorkerUgh... I tried using prebuilts but it's unreliable and needs an unfeasible
81*1c60b9acSAndroid Build Coastguard Workeramount of trust.  So I recommend bite the bullet and build your own... that's
82*1c60b9acSAndroid Build Coastguard Workertrivial on Linux but of course windows makes everything nasty.
83*1c60b9acSAndroid Build Coastguard Worker
84*1c60b9acSAndroid Build Coastguard WorkerAt least hopefully all the "research" is done and listed out here.
85*1c60b9acSAndroid Build Coastguard Worker
86*1c60b9acSAndroid Build Coastguard Worker#### OpenSSL build Prerequisite: install perl binary
87*1c60b9acSAndroid Build Coastguard Worker
88*1c60b9acSAndroid Build Coastguard WorkerMove the git version of perl out of the way, it won't work for OpenSSL build
89*1c60b9acSAndroid Build Coastguard Worker
90*1c60b9acSAndroid Build Coastguard Worker```
91*1c60b9acSAndroid Build Coastguard Workermv /usr/bin/perl /usr/bin/perl-git
92*1c60b9acSAndroid Build Coastguard Worker```
93*1c60b9acSAndroid Build Coastguard Worker
94*1c60b9acSAndroid Build Coastguard WorkerFor windows, OpenSSL "recommends" ActiveState perl but it doesn't work for me,
95*1c60b9acSAndroid Build Coastguard Workercomplaining about stuff needed from cpan and then dying when it was installed.
96*1c60b9acSAndroid Build Coastguard Worker"Strawberry Perl" is installed in `C:\Strawberry` and worked out the box.
97*1c60b9acSAndroid Build Coastguard Worker
98*1c60b9acSAndroid Build Coastguard Workerhttp://strawberryperl.com/download/5.30.2.1/strawberry-perl-5.30.2.1-64bit.msi
99*1c60b9acSAndroid Build Coastguard Worker
100*1c60b9acSAndroid Build Coastguard WorkerThe installer sets up `%PATH%` if you open a new cmd window.
101*1c60b9acSAndroid Build Coastguard Worker
102*1c60b9acSAndroid Build Coastguard Worker#### OpenSSL build Prerequisite: NASM
103*1c60b9acSAndroid Build Coastguard Worker
104*1c60b9acSAndroid Build Coastguard WorkerGo here and click on the latest stable, download the win32 .exe
105*1c60b9acSAndroid Build Coastguard Worker
106*1c60b9acSAndroid Build Coastguard Workerhttps://nasm.us/
107*1c60b9acSAndroid Build Coastguard Worker
108*1c60b9acSAndroid Build Coastguard WorkerJust install via the defaults.  Then add it to the PATH temporarily...
109*1c60b9acSAndroid Build Coastguard Worker
110*1c60b9acSAndroid Build Coastguard Worker```
111*1c60b9acSAndroid Build Coastguard Worker$ set PATH=%PATH%;C:\Program Files (x86)\NASM
112*1c60b9acSAndroid Build Coastguard Worker```
113*1c60b9acSAndroid Build Coastguard Worker
114*1c60b9acSAndroid Build Coastguard Worker#### OpenSSL build setup: source VC env vars
115*1c60b9acSAndroid Build Coastguard Worker
116*1c60b9acSAndroid Build Coastguard WorkerThese fix up the PATH and include dirs etc necessary for VC build in the cmd
117*1c60b9acSAndroid Build Coastguard Workerwindow.
118*1c60b9acSAndroid Build Coastguard Worker
119*1c60b9acSAndroid Build Coastguard Worker```
120*1c60b9acSAndroid Build Coastguard Worker$ call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
121*1c60b9acSAndroid Build Coastguard Worker```
122*1c60b9acSAndroid Build Coastguard Worker
123*1c60b9acSAndroid Build Coastguard Worker### OpenSSL build:
124*1c60b9acSAndroid Build Coastguard Worker
125*1c60b9acSAndroid Build Coastguard WorkerGrab openssl from git... assuming the prerequisites above went well it will
126*1c60b9acSAndroid Build Coastguard Workerjust sit there building for 30 minutes or whatever.
127*1c60b9acSAndroid Build Coastguard Worker
128*1c60b9acSAndroid Build Coastguard Worker```
129*1c60b9acSAndroid Build Coastguard Worker$ git clone https://github.com/openssl/openssl
130*1c60b9acSAndroid Build Coastguard Worker$ cd openssl
131*1c60b9acSAndroid Build Coastguard Worker$ perl Configure VC-WIN64A
132*1c60b9acSAndroid Build Coastguard Worker$ nmake
133*1c60b9acSAndroid Build Coastguard Worker```
134*1c60b9acSAndroid Build Coastguard Worker
135*1c60b9acSAndroid Build Coastguard WorkerAfterwards, open an Administrator mode cmd.exe, redo the msvc path and then
136*1c60b9acSAndroid Build Coastguard Workerinstall the build.
137*1c60b9acSAndroid Build Coastguard Worker
138*1c60b9acSAndroid Build Coastguard Worker```
139*1c60b9acSAndroid Build Coastguard Worker$ cd openssl
140*1c60b9acSAndroid Build Coastguard Worker$ call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
141*1c60b9acSAndroid Build Coastguard Worker$ nmake install
142*1c60b9acSAndroid Build Coastguard Worker```
143*1c60b9acSAndroid Build Coastguard Worker
144*1c60b9acSAndroid Build Coastguard WorkerOh another grindingly slow windows build action.  Finally it's in there in
145*1c60b9acSAndroid Build Coastguard Worker`C:\Program Files\OpenSSL`.
146*1c60b9acSAndroid Build Coastguard Worker
147*1c60b9acSAndroid Build Coastguard Workerlibraries are looking for a cert bundle at "C:\Program Files\Common Files\SSL\cert.pem"...
148*1c60b9acSAndroid Build Coastguard Workerit's not documented or included in the zip file from the above, so...
149*1c60b9acSAndroid Build Coastguard Worker
150*1c60b9acSAndroid Build Coastguard Worker#### Installing a cert bundle
151*1c60b9acSAndroid Build Coastguard Worker
152*1c60b9acSAndroid Build Coastguard WorkerYou can get a trusted cert bundle from here
153*1c60b9acSAndroid Build Coastguard Worker
154*1c60b9acSAndroid Build Coastguard Worker[drwetter/testssl cert bundle](https://raw.githubusercontent.com/drwetter/testssl.sh/3.1dev/etc/Microsoft.pem)
155*1c60b9acSAndroid Build Coastguard Worker
156*1c60b9acSAndroid Build Coastguard WorkerSave it into `C:\Program Files\Common Files\SSL\cert.pem` where openssl will be able to see it.
157*1c60b9acSAndroid Build Coastguard Worker
158*1c60b9acSAndroid Build Coastguard Worker## Required: pthreads
159*1c60b9acSAndroid Build Coastguard Worker
160*1c60b9acSAndroid Build Coastguard WorkerIt's amazing but after all these years windows doesn't offer pthreads compatibility
161*1c60b9acSAndroid Build Coastguard Workeritself.  Just like the many other missing POSIX bits like fork().
162*1c60b9acSAndroid Build Coastguard Worker
163*1c60b9acSAndroid Build Coastguard WorkerI downloaded the latest (2012) zip release of pthreads-win32 from here
164*1c60b9acSAndroid Build Coastguard Worker
165*1c60b9acSAndroid Build Coastguard Workerftp://sourceware.org/pub/pthreads-win32
166*1c60b9acSAndroid Build Coastguard Worker
167*1c60b9acSAndroid Build Coastguard WorkerThen I created a dir "C:\Program Files (x86)\pthreads", and copied the `dll`,
168*1c60b9acSAndroid Build Coastguard Worker`include` and `lib` subdirs from the `prebuilt` folder in the zip there.
169*1c60b9acSAndroid Build Coastguard Worker
170*1c60b9acSAndroid Build Coastguard WorkerThe cmake incantation to build against pthreads set up like that is
171*1c60b9acSAndroid Build Coastguard Worker
172*1c60b9acSAndroid Build Coastguard Worker```
173*1c60b9acSAndroid Build Coastguard Worker $ cmake .. -DLWS_HAVE_PTHREAD_H=1 -DLWS_EXT_PTHREAD_INCLUDE_DIR="C:\Program Files (x86)\pthreads\include" -DLWS_EXT_PTHREAD_LIBRARIES="C:\Program Files (x86)\pthreads\lib\x64\libpthreadGC2.a" -DLWS_WITH_MINIMAL_EXAMPLES=1
174*1c60b9acSAndroid Build Coastguard Worker```
175*1c60b9acSAndroid Build Coastguard Worker
176*1c60b9acSAndroid Build Coastguard Worker## Building libwebsockets
177*1c60b9acSAndroid Build Coastguard Worker
178*1c60b9acSAndroid Build Coastguard WorkerWe'll clone libwebsockets then use cmake to build via vs tools
179*1c60b9acSAndroid Build Coastguard Worker
180*1c60b9acSAndroid Build Coastguard Worker```
181*1c60b9acSAndroid Build Coastguard Worker> git clone https://libwebsockets.org/repo/libwebsockets
182*1c60b9acSAndroid Build Coastguard Worker> cd libwebsockets
183*1c60b9acSAndroid Build Coastguard Worker> mkdir build
184*1c60b9acSAndroid Build Coastguard Worker> cd build
185*1c60b9acSAndroid Build Coastguard Worker> cmake ..
186*1c60b9acSAndroid Build Coastguard Worker> cmake --build . --config DEBUG
187*1c60b9acSAndroid Build Coastguard Worker```
188*1c60b9acSAndroid Build Coastguard Worker
189*1c60b9acSAndroid Build Coastguard WorkerInstalling requires admin privs, I opened a second cmd window as admin and did it
190*1c60b9acSAndroid Build Coastguard Workerthere.
191*1c60b9acSAndroid Build Coastguard Worker
192*1c60b9acSAndroid Build Coastguard Worker```
193*1c60b9acSAndroid Build Coastguard Worker> cmake --install . --config DEBUG
194*1c60b9acSAndroid Build Coastguard Worker```
195*1c60b9acSAndroid Build Coastguard Worker
196*1c60b9acSAndroid Build Coastguard Worker### Hack the libs into view
197*1c60b9acSAndroid Build Coastguard Worker
198*1c60b9acSAndroid Build Coastguard WorkerThe libs we built against aren't visible in the system, I don't know what
199*1c60b9acSAndroid Build Coastguard WorkerReal Windows Programmers are supposed to do about that, but I used an Admin cmd
200*1c60b9acSAndroid Build Coastguard Workerprompt to copy them into C:\windows\system32
201*1c60b9acSAndroid Build Coastguard Worker
202*1c60b9acSAndroid Build Coastguard Worker```
203*1c60b9acSAndroid Build Coastguard Worker$ cp "C:\Program Files (x86)\pthreads\dll\x64\pthreadGC2.dll" "C:\Program Files\OpenSSL\bin\libcrypto-3.dll"  "C:\Program Files\OpenSSL\bin\libssl-3.dll" C:\Windows\system32
204*1c60b9acSAndroid Build Coastguard Worker```
205*1c60b9acSAndroid Build Coastguard Worker
206*1c60b9acSAndroid Build Coastguard WorkerAfter that you can run the test apps OK, eg
207*1c60b9acSAndroid Build Coastguard Worker
208*1c60b9acSAndroid Build Coastguard Worker```
209*1c60b9acSAndroid Build Coastguard Worker$ libwebsockets-test-server.exe -s
210*1c60b9acSAndroid Build Coastguard Worker```
211*1c60b9acSAndroid Build Coastguard Worker
212*1c60b9acSAndroid Build Coastguard Worker## Note about using paths with spaces in with cmake
213*1c60b9acSAndroid Build Coastguard Worker
214*1c60b9acSAndroid Build Coastguard Worker
215