xref: /netbsd-src/crypto/external/bsd/openssl/dist/NOTES-WINDOWS.md (revision b0d1725196a7921d003d2c66a14f186abda4176b)
1*b0d17251SchristosNotes for Windows platforms
2*b0d17251Schristos===========================
3*b0d17251Schristos
4*b0d17251Schristos - [Native builds using Visual C++](#native-builds-using-visual-c++)
5*b0d17251Schristos - [Native builds using Embarcadero C++Builder](
6*b0d17251Schristos   #native-builds-using-embarcadero-c++-builder)
7*b0d17251Schristos - [Native builds using MinGW](#native-builds-using-mingw)
8*b0d17251Schristos - [Linking native applications](#linking-native-applications)
9*b0d17251Schristos - [Hosted builds using Cygwin](#hosted-builds-using-cygwin)
10*b0d17251Schristos
11*b0d17251SchristosThere are various options to build and run OpenSSL on the Windows platforms.
12*b0d17251Schristos
13*b0d17251Schristos"Native" OpenSSL uses the Windows APIs directly at run time.
14*b0d17251SchristosTo build a native OpenSSL you can either use:
15*b0d17251Schristos
16*b0d17251Schristos    Microsoft Visual C++ (MSVC) C compiler on the command line
17*b0d17251Schristosor
18*b0d17251Schristos    Embarcadero C++Builder
19*b0d17251Schristosor
20*b0d17251Schristos    MinGW cross compiler
21*b0d17251Schristos    run on the GNU-like development environment MSYS2
22*b0d17251Schristos    or run on Linux or Cygwin
23*b0d17251Schristos
24*b0d17251Schristos"Hosted" OpenSSL relies on an external POSIX compatibility layer
25*b0d17251Schristosfor building (using GNU/Unix shell, compiler, and tools) and at run time.
26*b0d17251SchristosFor this option you can use Cygwin.
27*b0d17251Schristos
28*b0d17251SchristosNative builds using Visual C++
29*b0d17251Schristos==============================
30*b0d17251Schristos
31*b0d17251SchristosThe native builds using Visual C++ have a `VC-*` prefix.
32*b0d17251Schristos
33*b0d17251SchristosRequirement details
34*b0d17251Schristos-------------------
35*b0d17251Schristos
36*b0d17251SchristosIn addition to the requirements and instructions listed in `INSTALL.md`,
37*b0d17251Schristosthese are required as well:
38*b0d17251Schristos
39*b0d17251Schristos### Perl
40*b0d17251Schristos
41*b0d17251SchristosWe recommend Strawberry Perl, available from <http://strawberryperl.com/>
42*b0d17251SchristosPlease read NOTES.PERL for more information, including the use of CPAN.
43*b0d17251SchristosAn alternative is ActiveState Perl, <https://www.activestate.com/ActivePerl>
44*b0d17251Schristosfor which you may need to explicitly build the Perl module Win32/Console.pm
45*b0d17251Schristosvia <https://platform.activestate.com/ActiveState> and then download it.
46*b0d17251Schristos
47*b0d17251Schristos### Microsoft Visual C compiler.
48*b0d17251Schristos
49*b0d17251SchristosSince these are proprietary and ever-changing we cannot test them all.
50*b0d17251SchristosOlder versions may not work. Use a recent version wherever possible.
51*b0d17251Schristos
52*b0d17251Schristos### Netwide Assembler (NASM)
53*b0d17251Schristos
54*b0d17251SchristosNASM is the only supported assembler. It is available from <https://www.nasm.us>.
55*b0d17251Schristos
56*b0d17251SchristosQuick start
57*b0d17251Schristos-----------
58*b0d17251Schristos
59*b0d17251Schristos 1. Install Perl
60*b0d17251Schristos
61*b0d17251Schristos 2. Install NASM
62*b0d17251Schristos
63*b0d17251Schristos 3. Make sure both Perl and NASM are on your %PATH%
64*b0d17251Schristos
65*b0d17251Schristos 4. Use Visual Studio Developer Command Prompt with administrative privileges,
66*b0d17251Schristos    choosing one of its variants depending on the intended architecture.
67*b0d17251Schristos    Or run `cmd` and execute `vcvarsall.bat` with one of the options `x86`,
68*b0d17251Schristos    `x86_amd64`, `x86_arm`, `x86_arm64`, `amd64`, `amd64_x86`, `amd64_arm`,
69*b0d17251Schristos    or `amd64_arm64`.
70*b0d17251Schristos    This sets up the environment variables needed for `nmake.exe`, `cl.exe`,
71*b0d17251Schristos    etc.
72*b0d17251Schristos    See also
73*b0d17251Schristos    <https://docs.microsoft.com/cpp/build/building-on-the-command-line>
74*b0d17251Schristos
75*b0d17251Schristos 5. From the root of the OpenSSL source directory enter
76*b0d17251Schristos    - `perl Configure VC-WIN32`     if you want 32-bit OpenSSL or
77*b0d17251Schristos    - `perl Configure VC-WIN64A`    if you want 64-bit OpenSSL or
78*b0d17251Schristos    - `perl Configure VC-WIN64-ARM` if you want Windows on Arm (win-arm64)
79*b0d17251Schristos       OpenSSL or
80*b0d17251Schristos    - `perl Configure`              to let Configure figure out the platform
81*b0d17251Schristos
82*b0d17251Schristos 6. `nmake`
83*b0d17251Schristos
84*b0d17251Schristos 7. `nmake test`
85*b0d17251Schristos
86*b0d17251Schristos 8. `nmake install`
87*b0d17251Schristos
88*b0d17251SchristosFor the full installation instructions, or if anything goes wrong at any stage,
89*b0d17251Schristoscheck the INSTALL.md file.
90*b0d17251Schristos
91*b0d17251SchristosInstallation directories
92*b0d17251Schristos------------------------
93*b0d17251Schristos
94*b0d17251SchristosThe default installation directories are derived from environment
95*b0d17251Schristosvariables.
96*b0d17251Schristos
97*b0d17251SchristosFor VC-WIN32, the following defaults are use:
98*b0d17251Schristos
99*b0d17251Schristos    PREFIX:      %ProgramFiles(x86)%\OpenSSL
100*b0d17251Schristos    OPENSSLDIR:  %CommonProgramFiles(x86)%\SSL
101*b0d17251Schristos
102*b0d17251SchristosFor VC-WIN64, the following defaults are use:
103*b0d17251Schristos
104*b0d17251Schristos    PREFIX:      %ProgramW6432%\OpenSSL
105*b0d17251Schristos    OPENSSLDIR:  %CommonProgramW6432%\SSL
106*b0d17251Schristos
107*b0d17251SchristosShould those environment variables not exist (on a pure Win32
108*b0d17251Schristosinstallation for examples), these fallbacks are used:
109*b0d17251Schristos
110*b0d17251Schristos    PREFIX:      %ProgramFiles%\OpenSSL
111*b0d17251Schristos    OPENSSLDIR:  %CommonProgramFiles%\SSL
112*b0d17251Schristos
113*b0d17251SchristosALSO NOTE that those directories are usually write protected, even if
114*b0d17251Schristosyour account is in the Administrators group.  To work around that,
115*b0d17251Schristosstart the command prompt by right-clicking on it and choosing "Run as
116*b0d17251SchristosAdministrator" before running `nmake install`.  The other solution
117*b0d17251Schristosis, of course, to choose a different set of directories by using
118*b0d17251Schristos`--prefix` and `--openssldir` when configuring.
119*b0d17251Schristos
120*b0d17251SchristosSpecial notes for Universal Windows Platform builds, aka `VC-*-UWP`
121*b0d17251Schristos-------------------------------------------------------------------
122*b0d17251Schristos
123*b0d17251Schristos - UWP targets only support building the static and dynamic libraries.
124*b0d17251Schristos
125*b0d17251Schristos - You should define the platform type to `uwp` and the target arch via
126*b0d17251Schristos   `vcvarsall.bat` before you compile. For example, if you want to build
127*b0d17251Schristos   `arm64` builds, you should run `vcvarsall.bat x86_arm64 uwp`.
128*b0d17251Schristos
129*b0d17251SchristosNative builds using Embarcadero C++Builder
130*b0d17251Schristos=========================================
131*b0d17251Schristos
132*b0d17251SchristosThis toolchain (a descendant of Turbo/Borland C++) is an alternative to MSVC.
133*b0d17251SchristosOpenSSL currently includes an experimental 32-bit configuration targeting the
134*b0d17251SchristosClang-based compiler (`bcc32c.exe`) in v10.3.3 Community Edition.
135*b0d17251Schristos<https://www.embarcadero.com/products/cbuilder/starter>
136*b0d17251Schristos
137*b0d17251Schristos 1. Install Perl.
138*b0d17251Schristos
139*b0d17251Schristos 2. Open the RAD Studio Command Prompt.
140*b0d17251Schristos
141*b0d17251Schristos 3. Go to the root of the OpenSSL source directory and run:
142*b0d17251Schristos    `perl Configure BC-32 --prefix=%CD%`
143*b0d17251Schristos
144*b0d17251Schristos 4. `make -N`
145*b0d17251Schristos
146*b0d17251Schristos 5. `make -N test`
147*b0d17251Schristos
148*b0d17251Schristos 6. Build your program against this OpenSSL:
149*b0d17251Schristos    * Set your include search path to the "include" subdirectory of OpenSSL.
150*b0d17251Schristos    * Set your library search path to the OpenSSL source directory.
151*b0d17251Schristos
152*b0d17251SchristosNote that this is very experimental. Support for 64-bit and other Configure
153*b0d17251Schristosoptions is still pending.
154*b0d17251Schristos
155*b0d17251SchristosNative builds using MinGW
156*b0d17251Schristos=========================
157*b0d17251Schristos
158*b0d17251SchristosMinGW offers an alternative way to build native OpenSSL, by cross compilation.
159*b0d17251Schristos
160*b0d17251Schristos * Usually the build is done on Windows in a GNU-like environment called MSYS2.
161*b0d17251Schristos
162*b0d17251Schristos   MSYS2 provides GNU tools, a Unix-like command prompt,
163*b0d17251Schristos   and a UNIX compatibility layer for applications.
164*b0d17251Schristos   However, in this context it is only used for building OpenSSL.
165*b0d17251Schristos   The resulting OpenSSL does not rely on MSYS2 to run and is fully native.
166*b0d17251Schristos
167*b0d17251Schristos   Requirement details
168*b0d17251Schristos
169*b0d17251Schristos   - MSYS2 shell, from <https://www.msys2.org/>
170*b0d17251Schristos
171*b0d17251Schristos   - Perl, at least version 5.10.0, which usually comes pre-installed with MSYS2
172*b0d17251Schristos
173*b0d17251Schristos   - make, installed using `pacman -S make` into the MSYS2 environment
174*b0d17251Schristos
175*b0d17251Schristos   - MinGW[64] compiler: `mingw-w64-i686-gcc` and/or `mingw-w64-x86_64-gcc`.
176*b0d17251Schristos     These compilers must be on your MSYS2 $PATH.
177*b0d17251Schristos     A common error is to not have these on your $PATH.
178*b0d17251Schristos     The MSYS2 version of gcc will not work correctly here.
179*b0d17251Schristos
180*b0d17251Schristos   In the MSYS2 shell do the configuration depending on the target architecture:
181*b0d17251Schristos
182*b0d17251Schristos       ./Configure mingw ...
183*b0d17251Schristos
184*b0d17251Schristos   or
185*b0d17251Schristos
186*b0d17251Schristos       ./Configure mingw64 ...
187*b0d17251Schristos
188*b0d17251Schristos   or
189*b0d17251Schristos
190*b0d17251Schristos       ./Configure ...
191*b0d17251Schristos
192*b0d17251Schristos   for the default architecture.
193*b0d17251Schristos
194*b0d17251Schristos   Apart from that, follow the Unix / Linux instructions in `INSTALL.md`.
195*b0d17251Schristos
196*b0d17251Schristos * It is also possible to build mingw[64] on Linux or Cygwin.
197*b0d17251Schristos
198*b0d17251Schristos   In this case configure with the corresponding `--cross-compile-prefix=`
199*b0d17251Schristos   option. For example
200*b0d17251Schristos
201*b0d17251Schristos       ./Configure mingw --cross-compile-prefix=i686-w64-mingw32- ...
202*b0d17251Schristos
203*b0d17251Schristos   or
204*b0d17251Schristos
205*b0d17251Schristos       ./Configure mingw64 --cross-compile-prefix=x86_64-w64-mingw32- ...
206*b0d17251Schristos
207*b0d17251Schristos   This requires that you've installed the necessary add-on packages for
208*b0d17251Schristos   mingw[64] cross compilation.
209*b0d17251Schristos
210*b0d17251SchristosLinking native applications
211*b0d17251Schristos===========================
212*b0d17251Schristos
213*b0d17251SchristosThis section applies to all native builds.
214*b0d17251Schristos
215*b0d17251SchristosIf you link with static OpenSSL libraries then you're expected to
216*b0d17251Schristosadditionally link your application with `WS2_32.LIB`, `GDI32.LIB`,
217*b0d17251Schristos`ADVAPI32.LIB`, `CRYPT32.LIB` and `USER32.LIB`. Those developing
218*b0d17251Schristosnon-interactive service applications might feel concerned about
219*b0d17251Schristoslinking with `GDI32.LIB` and `USER32.LIB`, as they are justly associated
220*b0d17251Schristoswith interactive desktop, which is not available to service
221*b0d17251Schristosprocesses. The toolkit is designed to detect in which context it's
222*b0d17251Schristoscurrently executed, GUI, console app or service, and act accordingly,
223*b0d17251Schristosnamely whether or not to actually make GUI calls. Additionally those
224*b0d17251Schristoswho wish to `/DELAYLOAD:GDI32.DLL` and `/DELAYLOAD:USER32.DLL` and
225*b0d17251Schristosactually keep them off service process should consider implementing
226*b0d17251Schristosand exporting from .exe image in question own `_OPENSSL_isservice` not
227*b0d17251Schristosrelying on `USER32.DLL`. E.g., on Windows Vista and later you could:
228*b0d17251Schristos
229*b0d17251Schristos       __declspec(dllexport) __cdecl BOOL _OPENSSL_isservice(void)
230*b0d17251Schristos       {
231*b0d17251Schristos           DWORD sess;
232*b0d17251Schristos
233*b0d17251Schristos           if (ProcessIdToSessionId(GetCurrentProcessId(), &sess))
234*b0d17251Schristos               return sess == 0;
235*b0d17251Schristos           return FALSE;
236*b0d17251Schristos       }
237*b0d17251Schristos
238*b0d17251SchristosIf you link with OpenSSL .DLLs, then you're expected to include into
239*b0d17251Schristosyour application code a small "shim" snippet, which provides
240*b0d17251Schristosthe glue between the OpenSSL BIO layer and your compiler run-time.
241*b0d17251SchristosSee also the OPENSSL_Applink manual page.
242*b0d17251Schristos
243*b0d17251SchristosHosted builds using Cygwin
244*b0d17251Schristos==========================
245*b0d17251Schristos
246*b0d17251SchristosCygwin implements a POSIX/Unix runtime system (`cygwin1.dll`) on top of the
247*b0d17251SchristosWindows subsystem and provides a Bash shell and GNU tools environment.
248*b0d17251SchristosConsequently, a build of OpenSSL with Cygwin is virtually identical to the
249*b0d17251SchristosUnix procedure.
250*b0d17251Schristos
251*b0d17251SchristosTo build OpenSSL using Cygwin, you need to:
252*b0d17251Schristos
253*b0d17251Schristos * Install Cygwin, see <https://cygwin.com/>
254*b0d17251Schristos
255*b0d17251Schristos * Install Cygwin Perl, at least version 5.10.0
256*b0d17251Schristos   and ensure it is in the $PATH
257*b0d17251Schristos
258*b0d17251Schristos * Run the Cygwin Bash shell
259*b0d17251Schristos
260*b0d17251SchristosApart from that, follow the Unix / Linux instructions in INSTALL.md.
261*b0d17251Schristos
262*b0d17251SchristosNOTE: `make test` and normal file operations may fail in directories
263*b0d17251Schristosmounted as text (i.e. `mount -t c:\somewhere /home`) due to Cygwin
264*b0d17251Schristosstripping of carriage returns. To avoid this ensure that a binary
265*b0d17251Schristosmount is used, e.g. `mount -b c:\somewhere /home`.
266