[tor-commits] [tor/master] Build one big .a library full of Tor's implementation.

nickm at torproject.org nickm at torproject.org
Fri Oct 23 14:36:09 UTC 2020


commit e9dbb5e395097f4ae38d17cf27408c2688b90d2b
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Sep 18 12:17:02 2020 -0400

    Build one big .a library full of Tor's implementation.
    
    This is experimental and probably will break some platforms
---
 Makefile.am                           | 21 +++++++++++++++++++--
 scripts/build/combine_libs            | 35 +++++++++++++++++++++++++++++++++++
 scripts/codegen/fuzzing_include_am.py |  4 ++--
 src/app/include.am                    |  4 ++--
 src/test/include.am                   | 10 +++++-----
 5 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 136368088e..50b002139e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,6 +14,7 @@ CLEANFILES=
 TESTS=
 noinst_PROGRAMS=
 DISTCLEANFILES=
+MOSTLYCLEANFILES=
 bin_SCRIPTS=
 AM_CPPFLAGS=\
 	-I$(top_srcdir)/src \
@@ -137,6 +138,13 @@ TOR_INTERNAL_LIBS = \
 	src/trunnel/libor-trunnel.a \
 	src/lib/libtor-trace.a
 
+libtor.a: $(TOR_INTERNAL_LIBS)
+	$(AM_V_AR) export AR="$(AR)"; \
+	export ARFLAGS="$(ARFLAGS)"; \
+	$(top_srcdir)/scripts/build/combine_libs libtor.a $(TOR_INTERNAL_LIBS)
+
+MOSTLYCLEANFILES += libtor.a
+
 # Variants of the above for linking the testing variant of tor (for coverage
 # and tests)
 if UNITTESTS_ENABLED
@@ -148,6 +156,14 @@ TOR_INTERNAL_TESTING_LIBS = \
 	$(TOR_UTIL_TESTING_LIBS) \
 	src/trunnel/libor-trunnel-testing.a \
 	src/lib/libtor-trace.a
+
+src/test/libtor-testing.a: $(TOR_INTERNAL_TESTING_LIBS)
+	$(AM_V_AR) export AR="$(AR)"; \
+	export ARFLAGS="$(ARFLAGS)"; \
+	export RANLIB="$(RANLIB)"; \
+	$(top_srcdir)/scripts/build/combine_libs src/test/libtor-testing.a $(TOR_INTERNAL_TESTING_LIBS)
+
+MOSTLYCLEANFILES += src/test/libtor-testing.a
 endif
 
 TOR_LDFLAGS_CRYPTLIB=@TOR_LDFLAGS_openssl@
@@ -175,6 +191,7 @@ EXTRA_DIST+= \
 	Makefile.nmake							\
 	README								\
 	ReleaseNotes							\
+	scripts/build/combine_libs					\
 	scripts/maint/checkIncludes.py					\
 	scripts/maint/checkSpace.pl					\
 	scripts/maint/checkSpaceTest.sh					\
@@ -701,7 +718,7 @@ show-distdir-core:
 	  file $(distdir)/_build/core; fi
 
 show-libs:
-	@echo $(TOR_INTERNAL_LIBS)
+	@echo libtor.a
 
 show-testing-libs:
-	@echo $(TOR_INTERNAL_TESTING_LIBS)
+	@echo src/test/libtor-testing.a
diff --git a/scripts/build/combine_libs b/scripts/build/combine_libs
new file mode 100755
index 0000000000..fb311552fe
--- /dev/null
+++ b/scripts/build/combine_libs
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+set -e
+
+TMPDIR="$(mktemp -d -t tor_lib_combining.XXXXXX)"
+ORIGDIR="$(pwd)"
+
+trap 'cd "$ORIGDIR" && rm -rf "$TMPDIR"' 0
+
+abspath() {
+          echo "$(cd "$(dirname "$1")">/dev/null && pwd)/$(basename "$1")"
+}
+
+TARGET=$(abspath "$1")
+
+#echo ORIGDIR="$ORIGDIR"
+#echo AR="$AR"
+#echo ARFLAGS="$AFLAGS"
+
+shift
+
+for input in "$@"; do
+    cd "$ORIGDIR"
+    abs=$(abspath "$input")
+    dir="$TMPDIR"/$(basename "$input" .a)
+    mkdir "$dir"
+    cd "$dir">/dev/null
+    ar x "$abs"
+done
+
+cd "$TMPDIR" >/dev/null
+#echo "${AR:-ar}" "${ARFLAGS:-cru}" library.tmp.a ./*/**
+"${AR:-ar}" "${ARFLAGS:-cru}" library.tmp.a ./*/**
+"${RANLIB:-ranlib}" library.tmp.a
+mv -f library.tmp.a "$TARGET"
diff --git a/scripts/codegen/fuzzing_include_am.py b/scripts/codegen/fuzzing_include_am.py
index b3892b6fd3..3f8e51810b 100755
--- a/scripts/codegen/fuzzing_include_am.py
+++ b/scripts/codegen/fuzzing_include_am.py
@@ -31,7 +31,7 @@ FUZZING_CFLAGS = \
 FUZZING_LDFLAG = \
 	@TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) @TOR_LDFLAGS_libevent@
 FUZZING_LIBS = \
-	$(TOR_INTERNAL_TESTING_LIBS) \
+	src/test/libtor-testing.a \
 	$(rust_ldadd) \
 	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \
 	@TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \
@@ -41,7 +41,7 @@ FUZZING_LIBS = \
 	@TOR_ZSTD_LIBS@
 
 oss-fuzz-prereqs: \
-    $(TOR_INTERNAL_TESTING_LIBS)
+    src/test/libtor-testing.a
 
 noinst_HEADERS += \
 	src/test/fuzz/fuzzing.h
diff --git a/src/app/include.am b/src/app/include.am
index 8488a1bf19..b81fad0276 100644
--- a/src/app/include.am
+++ b/src/app/include.am
@@ -15,7 +15,7 @@ src_app_tor_SOURCES = src/app/main/tor_main.c
 # matters a lot there, and is quite hard to debug if you forget to do it.
 
 src_app_tor_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) @TOR_LDFLAGS_libevent@
-src_app_tor_LDADD = $(TOR_INTERNAL_LIBS) \
+src_app_tor_LDADD = libtor.a \
 	$(rust_ldadd) \
 	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \
 	@TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \
@@ -27,7 +27,7 @@ src_app_tor_cov_SOURCES = $(src_app_tor_SOURCES)
 src_app_tor_cov_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
 src_app_tor_cov_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
 src_app_tor_cov_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) @TOR_LDFLAGS_libevent@
-src_app_tor_cov_LDADD = $(TOR_INTERNAL_TESTING_LIBS) \
+src_app_tor_cov_LDADD = src/test/libtor-testing.a \
 	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \
 	@TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ \
 	@CURVE25519_LIBS@ @TOR_SYSTEMD_LIBS@ \
diff --git a/src/test/include.am b/src/test/include.am
index 816eba894e..fe55991f82 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -310,7 +310,7 @@ src_test_test_switch_id_LDADD = \
 src_test_test_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) \
 	@TOR_LDFLAGS_libevent@
 src_test_test_LDADD = \
-	$(TOR_INTERNAL_TESTING_LIBS) \
+	src/test/libtor-testing.a \
 	$(rust_ldadd) \
 	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \
 	$(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \
@@ -339,7 +339,7 @@ src_test_test_memwipe_LDFLAGS = $(src_test_test_LDFLAGS) @CFLAGS_BUGTRAP@
 src_test_bench_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) \
 	@TOR_LDFLAGS_libevent@
 src_test_bench_LDADD = \
-	$(TOR_INTERNAL_LIBS) \
+        libtor.a \
 	$(rust_ldadd) \
 	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \
 	$(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \
@@ -349,7 +349,7 @@ src_test_bench_LDADD = \
 src_test_test_workqueue_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) \
 	@TOR_LDFLAGS_libevent@
 src_test_test_workqueue_LDADD = \
-	$(TOR_INTERNAL_TESTING_LIBS) \
+        src/test/libtor-testing.a \
 	$(rust_ldadd) \
 	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \
 	$(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \
@@ -398,7 +398,7 @@ noinst_PROGRAMS+= src/test/test-hs-ntor-cl
 src_test_test_ntor_cl_SOURCES  = src/test/test_ntor_cl.c
 src_test_test_ntor_cl_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB)
 src_test_test_ntor_cl_LDADD = \
-	$(TOR_INTERNAL_LIBS) \
+	libtor.a \
 	$(rust_ldadd) \
 	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \
 	$(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \
@@ -409,7 +409,7 @@ src_test_test_ntor_cl_AM_CPPFLAGS =	       \
 src_test_test_hs_ntor_cl_SOURCES  = src/test/test_hs_ntor_cl.c
 src_test_test_hs_ntor_cl_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB)
 src_test_test_hs_ntor_cl_LDADD = \
-	$(TOR_INTERNAL_LIBS) \
+	libtor.a \
 	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \
 	$(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ \
         @CURVE25519_LIBS@ @TOR_TRACE_LIBS@





More information about the tor-commits mailing list