randombit / botan

Cryptography Toolkit
https://botan.randombit.net
BSD 2-Clause "Simplified" License
2.59k stars 567 forks source link

How to build on windows with MSVC2022 and --with-build-dir #3607

Closed ridilculous closed 1 year ago

ridilculous commented 1 year ago

I'm not sure if this is a bug or if i'm using it wrong but whatever i try it seems like --with-build-dir is ignored by the following nmake.

Here's how i'm testing (using the release-3 branch):

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat
python configure.py --cc=msvc --os=windows --debug-mode --with-build-dir=build_debug
nmake

I also tried .\build_debug and an absolute path but nmake always tries to build in the build dir. It works when i don't use --with-build-dir.

This is the output i get:

C:\dev\libs\botan>python configure.py --cc=msvc --os=windows --debug-mode --with-build-dir=build_debug
   INFO: configure.py invoked with options "--cc=msvc --os=windows --debug-mode --with-build-dir=build_debug"
   INFO: Configuring to build Botan 3.0.0 (revision git:51b06ca93d1998d19927699f78b8d67539148dde)
   INFO: Running under 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
   INFO: Autodetected platform information: OS="Windows" machine="AMD64" proc="AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD"
   INFO: Guessing target processor is a x86_64 (use --cpu to set)
   INFO: Canonicalized CPU target AMD64 to x86_64
   INFO: Auto-detected compiler version 19.36
   INFO: Auto-detected compiler arch x86_64
   INFO: Target is msvc:19.36-windows-x86_64
   INFO: Assuming target x86_64 is little endian
   INFO: Skipping (dependency failure): asio certstor_sqlite3 sessions_sqlite3
   INFO: Skipping (incompatible CPU): aes_armv8 aes_power8 sha1_armv8 sha2_32_armv8 shacal2_armv8 sm4_armv8
   INFO: Skipping (incompatible OS): certstor_system_macos commoncrypto fd_unix getentropy
   INFO: Skipping (incompatible compiler): argon2_ssse3 serpent_avx2 sha2_32_bmi2 sha2_64_bmi2 sha3_bmi2
   INFO: Skipping (no enabled compression schemes): compression
   INFO: Skipping (requires external dependency): boost bzip2 lzma sqlite3 tpm zlib
   INFO: Loading modules: adler32 aead aes aes_ni aes_vperm argon2 argon2_avx2 argon2fmt aria asn1 auto_rng base base32 base58 base64 bcrypt bcrypt_pbkdf bigint blake2 blake2mac block blowfish camellia cascade cast128 cbc ccm certstor_flatfile certstor_sql certstor_system certstor_system_windows cfb chacha chacha20poly1305 chacha_avx2 chacha_rng chacha_simd32 checksum cmac comb4p cpuid crc24 crc32 cryptobox ctr curve25519 des dh dilithium dilithium_aes dilithium_common dl_algo dl_group dlies dsa dyn_load eax ec_group ec_h2c ecc_key ecdh ecdsa ecgdsa ecies eckcdsa ed25519 elgamal eme_oaep eme_pkcs1 eme_raw emsa_pkcs1 emsa_pssr emsa_raw emsa_x931 entropy ffi filters fpe_fe1 gcm ghash ghash_cpu ghash_vperm gmac gost_28147 gost_3410 gost_3411 hash hash_id hex hkdf hmac hmac_drbg hotp http_util idea idea_sse2 iso9796 kdf kdf1 kdf1_iso18033 kdf2 keccak keypair kyber kyber_90s kyber_common lion locking_allocator mac mce md4 md5 mdx_hash mem_pool mgf1 mode_pad modes mp nist_keywrap noekeon noekeon_simd numbertheory ocb ofb par_hash passhash9 pbes2 pbkdf pbkdf2 pem pgp_s2k pk_pad pkcs11 poly1305 poly_dbl prf_tls prf_x942 processor_rng psk_db pubkey raw_hash rc4 rdseed rfc3394 rfc6979 rmd160 rng roughtime rsa salsa20 scrypt seed serpent serpent_simd sessions_sql sha1 sha1_sse2 sha1_x86 sha2_32 sha2_32_x86 sha2_64 sha3 shacal2 shacal2_avx2 shacal2_simd shacal2_x86 shake shake_cipher simd simd_avx2 siphash siv skein sm2 sm3 sm4 socket sodium sp800_108 sp800_56a sp800_56c srp6 stateful_rng stream streebog system_rng thread_utils threefish_512 tls tls12 tls13 tls_cbc trunc_hash tss twofish utils uuid whirlpool win32_stats x509 x919_mac xmss xts zfec zfec_sse2 zfec_vperm
   INFO: Using hardlink to link files into build dir (use --link-method to change)
   INFO: Botan 3.0.0 (revision git:51b06ca93d1998d19927699f78b8d67539148dde) (unreleased undated) build setup is complete

C:\dev\libs\botan>nmake

Microsoft (R) Program Maintenance Utility Version 14.36.32532.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl /DBOTAN_DLL=__declspec(dllexport) /Fdbuild/botan-3.pdb  /std:c++20 /EHs /GR /D_WIN32_WINNT=0x0600 /MDd /bigobj /Zi /FS -DBOTAN_IS_BEING_BUILT /W4 /wd4251 /wd4275 /wd5072  /I build/include /external:W0 /external:I build/include/external /nologo /c src/lib/asn1/alg_id.cpp /Fobuild/obj/lib/asn1_alg_id.obj
alg_id.cpp
src/lib/asn1/alg_id.cpp: fatal error C1041: cannot open program database 'C:\dev\libs\botan\build\botan-3.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS
NMAKE : fatal error U1077: 'cl /DBOTAN_DLL=__declspec(dllexport) /Fdbuild/botan-3.pdb  /std:c++20 /EHs /GR /D_WIN32_WINNT=0x0600 /MDd /bigobj /Zi /FS -DBOTAN_IS_BEING_BUILT /W4 /wd4251 /wd4275 /wd5072  /I build/include /external:W0 /external:I build/include/external /nologo /c src/lib/asn1/alg_id.cpp /Fobuild/obj/lib/asn1_alg_id.obj' : return code '0x2'
Stop.
randombit commented 1 year ago

How --build-dir= works right now is kind of funky and probably not matching your expectations. It sets up the entire build relative to some directory x, but expects make to be invoked still from the root directory. Here is it operating on Linux

$ ./configure.py --build-dir=/tmp/x
...
$ make -f /tmp/x/Makefile
...

I think (besides path differences) this should also work on Windows with nmake.

ridilculous commented 1 year ago

Ahh. Thanks a lot for pointing this out! I didn't notice that the release build put the Makefile in the root. This works perfectly:

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat
python configure.py --cc=msvc --os=windows --debug-mode --with-build-dir=build/debug --program-suffix=D.exe --library-suffix=D
nmake /F build/debug/Makefile
nmake /F build/debug/Makefile check

On another note, even though it makes completely sense, it wasn't clear to me from the docs that when set, --program-suffix needs an explicit .exe suffix.