@@ -227,17 +227,12 @@ ENSUREPIP= @ENSUREPIP@
227227# Internal static libraries
228228LIBMPDEC_A= Modules/_decimal/libmpdec/libmpdec.a
229229LIBEXPAT_A= Modules/expat/libexpat.a
230- LIBHACL_MD5_A= Modules/_hacl/libHacl_Hash_MD5.a
231- LIBHACL_SHA1_A= Modules/_hacl/libHacl_Hash_SHA1.a
232- LIBHACL_SHA2_A= Modules/_hacl/libHacl_Hash_SHA2.a
233- LIBHACL_SHA3_A= Modules/_hacl/libHacl_Hash_SHA3.a
234- LIBHACL_BLAKE2_A= Modules/_hacl/libHacl_Hash_Blake2.a
235- LIBHACL_HMAC_A= Modules/_hacl/libHacl_HMAC.a
230+
231+ # HACL* build configuration
236232LIBHACL_CFLAGS=@LIBHACL_CFLAGS@
237- LIBHACL_SIMD128_FLAGS=@LIBHACL_SIMD128_FLAGS@
238- LIBHACL_SIMD256_FLAGS=@LIBHACL_SIMD256_FLAGS@
239- LIBHACL_SIMD128_OBJS=@LIBHACL_SIMD128_OBJS@
240- LIBHACL_SIMD256_OBJS=@LIBHACL_SIMD256_OBJS@
233+ LIBHACL_LDFLAGS=@LIBHACL_LDFLAGS@
234+ LIBHACL_BLAKE2_SIMD128_CFLAGS=@LIBHACL_SIMD128_FLAGS@ -DHACL_CAN_COMPILE_VEC128
235+ LIBHACL_BLAKE2_SIMD256_CFLAGS=@LIBHACL_SIMD256_FLAGS@ -DHACL_CAN_COMPILE_VEC256
241236
242237# Module state, compiler flags and linker flags
243238# Empty CFLAGS and LDFLAGS are omitted.
@@ -660,25 +655,40 @@ LIBEXPAT_HEADERS= \
660655
661656##########################################################################
662657# hashlib's HACL* library
658+ #
659+ # On WASI, static build is required.
660+ # On other platforms, a shared library is used.
663661
664662LIBHACL_MD5_OBJS= \
665663 Modules/_hacl/Hacl_Hash_MD5.o
664+ LIBHACL_MD5_LIB_STATIC=Modules/_hacl/libHacl_Hash_MD5.a
665+ LIBHACL_MD5_LIB_SHARED=$(LIBHACL_MD5_OBJS)
666666
667667LIBHACL_SHA1_OBJS= \
668668 Modules/_hacl/Hacl_Hash_SHA1.o
669+ LIBHACL_SHA1_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA1.a
670+ LIBHACL_SHA1_LIB_SHARED=$(LIBHACL_SHA1_OBJS)
669671
670672LIBHACL_SHA2_OBJS= \
671673 Modules/_hacl/Hacl_Hash_SHA2.o
674+ LIBHACL_SHA2_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA2.a
675+ LIBHACL_SHA2_LIB_SHARED=$(LIBHACL_SHA2_OBJS)
672676
673677LIBHACL_SHA3_OBJS= \
674678 Modules/_hacl/Hacl_Hash_SHA3.o
679+ LIBHACL_SHA3_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA3.a
680+ LIBHACL_SHA3_LIB_SHARED=$(LIBHACL_SHA3_OBJS)
675681
682+ LIBHACL_BLAKE2_SIMD128_OBJS=@LIBHACL_BLAKE2_SIMD128_OBJS@
683+ LIBHACL_BLAKE2_SIMD256_OBJS=@LIBHACL_BLAKE2_SIMD256_OBJS@
676684LIBHACL_BLAKE2_OBJS= \
677685 Modules/_hacl/Hacl_Hash_Blake2s.o \
678686 Modules/_hacl/Hacl_Hash_Blake2b.o \
679687 Modules/_hacl/Lib_Memzero0.o \
680- $(LIBHACL_SIMD128_OBJS) \
681- $(LIBHACL_SIMD256_OBJS)
688+ $(LIBHACL_BLAKE2_SIMD128_OBJS) \
689+ $(LIBHACL_BLAKE2_SIMD256_OBJS)
690+ LIBHACL_BLAKE2_LIB_STATIC=Modules/_hacl/libHacl_Hash_BLAKE2.a
691+ LIBHACL_BLAKE2_LIB_SHARED=$(LIBHACL_BLAKE2_OBJS)
682692
683693LIBHACL_HMAC_OBJS= \
684694 Modules/_hacl/Hacl_HMAC.o \
@@ -688,6 +698,8 @@ LIBHACL_HMAC_OBJS= \
688698 $(LIBHACL_SHA2_OBJS) \
689699 $(LIBHACL_SHA3_OBJS) \
690700 $(LIBHACL_BLAKE2_OBJS)
701+ LIBHACL_HMAC_LIB_STATIC=Modules/_hacl/libHacl_HMAC.a
702+ LIBHACL_HMAC_LIB_SHARED=$(LIBHACL_HMAC_OBJS)
691703
692704LIBHACL_HEADERS= \
693705 Modules/_hacl/include/krml/FStar_UInt128_Verified.h \
@@ -732,7 +744,6 @@ LIBHACL_BLAKE2_HEADERS= \
732744 Modules/_hacl/internal/Hacl_Impl_Blake2_Constants.h \
733745 Modules/_hacl/internal/Hacl_Hash_Blake2s_Simd128.h \
734746 Modules/_hacl/internal/Hacl_Hash_Blake2b_Simd256.h \
735- Modules/_hacl/internal/Hacl_Streaming_Types.h \
736747 $(LIBHACL_HEADERS)
737748
738749LIBHACL_HMAC_HEADERS= \
@@ -1461,74 +1472,72 @@ $(LIBEXPAT_A): $(LIBEXPAT_OBJS)
14611472 $(AR) $(ARFLAGS) $@ $(LIBEXPAT_OBJS)
14621473
14631474##########################################################################
1464- # Build HACL* static libraries for hashlib and HACL* HMAC.
1475+ # HACL* library build
1476+ #
1477+ # The HACL* modules are dynamically compiled and linked with the
1478+ # corresponding CPython built-in modules on demand, depending on
1479+ # whether the module is built or not.
14651480#
1466- # The contents of libHacl_Blake2.a vary depending on whether we
1467- # have the ability to compile vectorized versions
1481+ # In particular, the HACL* objects are also dependencies of the
1482+ # corresponding C extension modules but makesetup must NOT create
1483+ # a rule for them.
1484+ #
1485+ # For WASI, static linking is needed and HACL* is statically linked instead.
1486+
1487+ Modules/_hacl/Lib_Memzero0.o: $(srcdir)/Modules/_hacl/Lib_Memzero0.c $(LIBHACL_HEADERS)
1488+ $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Lib_Memzero0.c
14681489
14691490Modules/_hacl/Hacl_Hash_MD5.o: $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c $(LIBHACL_MD5_HEADERS)
14701491 $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c
1471-
1472- $(LIBHACL_MD5_A): $(LIBHACL_MD5_OBJS)
1492+ $(LIBHACL_MD5_LIB_STATIC): $(LIBHACL_MD5_OBJS)
14731493 -rm -f $@
14741494 $(AR) $(ARFLAGS) $@ $(LIBHACL_MD5_OBJS)
14751495
14761496Modules/_hacl/Hacl_Hash_SHA1.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c $(LIBHACL_SHA1_HEADERS)
14771497 $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c
1478-
1479- $(LIBHACL_SHA1_A): $(LIBHACL_SHA1_OBJS)
1498+ $(LIBHACL_SHA1_LIB_STATIC): $(LIBHACL_SHA1_OBJS)
14801499 -rm -f $@
14811500 $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA1_OBJS)
14821501
14831502Modules/_hacl/Hacl_Hash_SHA2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c $(LIBHACL_SHA2_HEADERS)
14841503 $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c
1485-
1486- $(LIBHACL_SHA2_A): $(LIBHACL_SHA2_OBJS)
1504+ $(LIBHACL_SHA2_LIB_STATIC): $(LIBHACL_SHA2_OBJS)
14871505 -rm -f $@
14881506 $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA2_OBJS)
14891507
14901508Modules/_hacl/Hacl_Hash_SHA3.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c $(LIBHACL_SHA3_HEADERS)
14911509 $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c
1492-
1493- $(LIBHACL_SHA3_A): $(LIBHACL_SHA3_OBJS)
1510+ $(LIBHACL_SHA3_LIB_STATIC): $(LIBHACL_SHA3_OBJS)
14941511 -rm -f $@
14951512 $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA3_OBJS)
14961513
14971514Modules/_hacl/Hacl_Hash_Blake2s.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c $(LIBHACL_BLAKE2_HEADERS)
14981515 $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c
1499-
15001516Modules/_hacl/Hacl_Hash_Blake2b.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b.c $(LIBHACL_BLAKE2_HEADERS)
15011517 $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b.c
1502-
15031518Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c $(LIBHACL_BLAKE2_HEADERS)
1504- $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD128_FLAGS) -DHACL_CAN_COMPILE_VEC128 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c
1505-
1519+ $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD128_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c
15061520Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c $(LIBHACL_BLAKE2_HEADERS)
1507- $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD128_FLAGS) -DHACL_CAN_COMPILE_VEC128 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c
1508-
1521+ $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD128_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c
15091522Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c $(LIBHACL_BLAKE2_HEADERS)
1510- $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD256_FLAGS) -DHACL_CAN_COMPILE_VEC256 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c
1511-
1523+ $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD256_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c
15121524Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c $(LIBHACL_BLAKE2_HEADERS)
1513- $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD256_FLAGS) -DHACL_CAN_COMPILE_VEC256 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c
1514-
1515- Modules/_hacl/Lib_Memzero0.o: $(srcdir)/Modules/_hacl/Lib_Memzero0.c $(LIBHACL_BLAKE2_HEADERS)
1516- $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Lib_Memzero0.c
1517-
1518- $(LIBHACL_BLAKE2_A): $(LIBHACL_BLAKE2_OBJS)
1525+ $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD256_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c
1526+ $(LIBHACL_BLAKE2_LIB_STATIC): $(LIBHACL_BLAKE2_OBJS)
15191527 -rm -f $@
15201528 $(AR) $(ARFLAGS) $@ $(LIBHACL_BLAKE2_OBJS)
15211529
1530+ # Other HACL* cryptographic primitives
1531+
15221532Modules/_hacl/Hacl_HMAC.o: $(srcdir)/Modules/_hacl/Hacl_HMAC.c $(LIBHACL_HMAC_HEADERS)
15231533 $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_HMAC.c
1524-
15251534Modules/_hacl/Hacl_Streaming_HMAC.o: $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c $(LIBHACL_HMAC_HEADERS)
15261535 $(CC) -Wno-unused-variable -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c
1527-
1528- $(LIBHACL_HMAC_A): $(LIBHACL_HMAC_OBJS)
1536+ $(LIBHACL_HMAC_LIB_STATIC): $(LIBHACL_HMAC_OBJS)
15291537 -rm -f $@
15301538 $(AR) $(ARFLAGS) $@ $(LIBHACL_HMAC_OBJS)
15311539
1540+ ##########################################################################
15321541# create relative links from build/lib.platform/egg.so to Modules/egg.so
15331542# pybuilddir.txt is created too late. We cannot use it in Makefile
15341543# targets. ln --relative is not portable.
@@ -3302,12 +3311,21 @@ MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h @LIBMPDEC_INTERNAL@
33023311MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/pyexpat.c @LIBEXPAT_INTERNAL@
33033312MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h
33043313MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h
3305- MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) $(LIBHACL_MD5_A)
3306- MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) $(LIBHACL_SHA1_A)
3307- MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(LIBHACL_SHA2_A)
3308- MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) $(LIBHACL_SHA3_A)
3309- MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) $(LIBHACL_BLAKE2_A)
3310- MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) $(LIBHACL_HMAC_A)
3314+
3315+ # HACL*-based cryptographic primitives
3316+ MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) $(LIBHACL_MD5_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3317+ MODULE__MD5_LDEPS=$(LIBHACL_MD5_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3318+ MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) $(LIBHACL_SHA1_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3319+ MODULE__SHA1_LDEPS=$(LIBHACL_SHA1_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3320+ MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(LIBHACL_SHA2_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3321+ MODULE__SHA2_LDEPS=$(LIBHACL_SHA2_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3322+ MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) $(LIBHACL_SHA3_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3323+ MODULE__SHA3_LDEPS=$(LIBHACL_SHA3_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3324+ MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) $(LIBHACL_BLAKE2_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3325+ MODULE__BLAKE2_LDEPS=$(LIBHACL_BLAKE2_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3326+ MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) $(LIBHACL_HMAC_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3327+ MODULE__HMAC_LDEPS=$(LIBHACL_HMAC_LIB_@LIBHACL_LDEPS_LIBTYPE@)
3328+
33113329MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c
33123330MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h
33133331MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h
0 commit comments