From 548aca02e77716d3126074dc807634e98fe903bb Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 6 Apr 2021 13:57:34 -0600 Subject: [PATCH] configure and makesfiles: make code compression more configurable Add a `configure` argument to enable even more compression in ".zo" forms, and introduce environment variables to enable compression control for Windows builds using MSVC. --- racket/src/cs/c/configure | 11 +++++++++++ racket/src/cs/c/configure.ac | 5 +++++ racket/src/cs/compile-file.ss | 6 ++++++ racket/src/worksp/.gitignore | 3 +++ racket/src/worksp/README.txt | 6 ++++++ racket/src/worksp/cs/Makefile | 10 +++++++++- racket/src/worksp/cs/lz4.c | 9 +++++++++ racket/src/worksp/cs/lz4.def | 4 ++++ racket/src/worksp/csbuild.rkt | 28 ++++++++++++++++++++-------- 9 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 racket/src/worksp/cs/lz4.c create mode 100644 racket/src/worksp/cs/lz4.def diff --git a/racket/src/cs/c/configure b/racket/src/cs/c/configure index 91ee4c58e6..e126eeb446 100755 --- a/racket/src/cs/c/configure +++ b/racket/src/cs/c/configure @@ -783,6 +783,7 @@ enable_pthread enable_iconv enable_wpo enable_compress +enable_compressmore enable_compressboot enable_origtree enable_sharezo @@ -1432,6 +1433,7 @@ Optional Features: --enable-iconv use iconv (usually auto-enabled) --enable-wpo agressively optimize Racket core (enabled by default) --enable-compress compress compiled code (enabled by default) + --enable-compressmore compress compiled code even more --enable-compressboot compress boot files --enable-origtree install with original directory structure --enable-sharezo install ".zo"s to "share", not "lib" @@ -2550,6 +2552,11 @@ if test "${enable_compress+set}" = set; then : enableval=$enable_compress; fi +# Check whether --enable-compressmore was given. +if test "${enable_compressmore+set}" = set; then : + enableval=$enable_compressmore; +fi + # Check whether --enable-compressboot was given. if test "${enable_compressboot+set}" = set; then : enableval=$enable_compressboot; @@ -2821,6 +2828,7 @@ fi show_explicitly_enabled "${enable_pthread}" "pthreads" show_explicitly_disabled "${enable_pthread}" "pthreads" show_explicitly_disabled "${enable_compress}" "Compressed code" +show_explicitly_disabled "${enable_compressmore}" "Compressed code even more" show_explicitly_enabled "${enable_compressboot}" "Compressed boot files" show_explicitly_enabled "${enable_xonx}" "Unix style" show_explicitly_enabled "${enable_libzo}" 'Compiled ".zo" files moved to lib' @@ -4677,6 +4685,9 @@ fi if test "${enable_compress}" != "no" ; then COMPRESS_COMP="--compress" fi +if test "${enable_compressmore}" = "yes" ; then + COMPRESS_COMP="--compress-more" +fi if test "${enable_compressboot}" = "yes" ; then BOOT_COMPRESS_COMP="--compress" diff --git a/racket/src/cs/c/configure.ac b/racket/src/cs/c/configure.ac index cce93252e6..13b16ba2b0 100644 --- a/racket/src/cs/c/configure.ac +++ b/racket/src/cs/c/configure.ac @@ -18,6 +18,7 @@ AC_ARG_ENABLE(pthread, [ --enable-pthread link with pthreads (usually AC_ARG_ENABLE(iconv, [ --enable-iconv use iconv (usually auto-enabled)]) AC_ARG_ENABLE(wpo, [ --enable-wpo agressively optimize Racket core (enabled by default)]) AC_ARG_ENABLE(compress, [ --enable-compress compress compiled code (enabled by default)]) +AC_ARG_ENABLE(compressmore, [ --enable-compressmore compress compiled code even more]) AC_ARG_ENABLE(compressboot, [ --enable-compressboot compress boot files]) m4_include(../ac/path_arg.m4) AC_ARG_ENABLE(racket, [ --enable-racket= use as Racket for build; or "auto" to create]) @@ -72,6 +73,7 @@ fi show_explicitly_enabled "${enable_pthread}" "pthreads" show_explicitly_disabled "${enable_pthread}" "pthreads" show_explicitly_disabled "${enable_compress}" "Compressed code" +show_explicitly_disabled "${enable_compressmore}" "Compressed code even more" show_explicitly_enabled "${enable_compressboot}" "Compressed boot files" show_explicitly_enabled "${enable_xonx}" "Unix style" m4_include(../ac/path_show.m4) @@ -489,6 +491,9 @@ fi if test "${enable_compress}" != "no" ; then COMPRESS_COMP="--compress" fi +if test "${enable_compressmore}" = "yes" ; then + COMPRESS_COMP="--compress-more" +fi if test "${enable_compressboot}" = "yes" ; then BOOT_COMPRESS_COMP="--compress" diff --git a/racket/src/cs/compile-file.ss b/racket/src/cs/compile-file.ss index 198b700e67..83dc818ddc 100644 --- a/racket/src/cs/compile-file.ss +++ b/racket/src/cs/compile-file.ss @@ -67,6 +67,12 @@ (fasl-compressed #t) (putenv "PLT_CS_MAKE_COMPRESSED" "y") ; for "linklet.sls" (loop args))] + [(get-opt args "--compress-more" 0) + => (lambda (args) + (fasl-compressed #t) + (putenv "PLT_CS_MAKE_COMPRESSED" "y") ; for "linklet.sls" + (putenv "PLT_CS_MAKE_COMPRESSED_DATA" "y") ; ditto + (loop args))] [(get-opt args "--whole-program" 0) => (lambda (args) (set! whole-program? #t) diff --git a/racket/src/worksp/.gitignore b/racket/src/worksp/.gitignore index 391cca548c..bedb80ed2a 100644 --- a/racket/src/worksp/.gitignore +++ b/racket/src/worksp/.gitignore @@ -39,3 +39,6 @@ cstartup.exe /bc_suffix_new.h /compiled +/liblz4.dll +/liblz4.lib +/liblz4.exp diff --git a/racket/src/worksp/README.txt b/racket/src/worksp/README.txt index f8d153549e..2650173ba7 100644 --- a/racket/src/worksp/README.txt +++ b/racket/src/worksp/README.txt @@ -50,6 +50,12 @@ Many intermediate files will be put in "../build". To add a "CS" suffix to the generated executables, call "csbuild.rkt" with `--racketcs-suffix "CS"`. +To enable compression of embedded boot files, set the +`PLT_BOOTFILE_COMPRESS` environment variable (to anything). To +increase compression of compiled code (at the expense of load times), +set the `PLT_CS_MAKE_COMPRESSED_DATA`. To instead disable the +compression of compiled code, set `PLT_CS_MAKE_NO_COMPRESSED`. + See also "Completing the Build" below. Racket BC diff --git a/racket/src/worksp/cs/Makefile b/racket/src/worksp/cs/Makefile index 237002d40f..953223c8c4 100644 --- a/racket/src/worksp/cs/Makefile +++ b/racket/src/worksp/cs/Makefile @@ -10,6 +10,9 @@ LIBS = $(RKTIO_LIB) \ $(SCHEME_LIB_FULL) \ $(WIN32_LIBS) +LZ4_DLL = ..\liblz4.dll +LZ4_LIB = $(SCHEME_DIR)\$(MACHINE)\lz4\lib\liblz4.lib + DEST_DLL = ..\..\build\raw_libracketcs.dll DEST = ..\..\build\raw_racketcs.exe GDEST = ..\..\build\raw_gracketcs.exe @@ -27,7 +30,7 @@ MEMMOD = ..\..\start\MemoryModule.c FLAGS = /DWIN32 /Ox /MT /GF COMP_SUBDIR = /DCS_COMPILED_SUBDIR=1 -all: $(DEST) $(GDEST) +all: $(DEST) $(GDEST) $(LZ4_DLL) $(DEST_DLL): $(CSDIR)\boot.c libracket.res $(RKTIO_LIB) $(SCHEME_LIB_FULL) cl /LD /DLL /Fe$(DEST_DLL) $(FLAGS) $(INCS) $(CSDIR)\boot.c libracket.res $(LIBS) @@ -47,6 +50,11 @@ $(GDEST): $(CSDIR)\grmain.c $(CSDIR)\main.c $(MAIN_DEPS) $(DEST_DLL) gracket.res gracket.res: ../gracket/gracket.rc ../gracket/gracket.ico rc /l 0x409 /fogracket.res ../gracket/gracket.rc +# Useful for adjusting boot file compression: + +$(LZ4_DLL): lz4.c lz4.def + cl /LD /DLL /Fe$(LZ4_DLL) $(FLAGS) lz4.c $(LZ4_LIB) $(WIN32_LIBS) /link /DEF:lz4.def + # Useful for debugging: RKTIO_DLL = ..\..\lib\librktio.dll diff --git a/racket/src/worksp/cs/lz4.c b/racket/src/worksp/cs/lz4.c new file mode 100644 index 0000000000..d0641921e0 --- /dev/null +++ b/racket/src/worksp/cs/lz4.c @@ -0,0 +1,9 @@ +extern void LZ4_decompress_safe(void); +extern void LZ4_compressBound(void); +extern void LZ4_compress_default(void); + +void lz4_stub(void) { + LZ4_decompress_safe(); + LZ4_compressBound(); + LZ4_compress_default(); +} diff --git a/racket/src/worksp/cs/lz4.def b/racket/src/worksp/cs/lz4.def new file mode 100644 index 0000000000..5280790aa5 --- /dev/null +++ b/racket/src/worksp/cs/lz4.def @@ -0,0 +1,4 @@ +EXPORTS + LZ4_decompress_safe + LZ4_compressBound + LZ4_compress_default diff --git a/racket/src/worksp/csbuild.rkt b/racket/src/worksp/csbuild.rkt index 329f91e6f6..52a0ba8f68 100644 --- a/racket/src/worksp/csbuild.rkt +++ b/racket/src/worksp/csbuild.rkt @@ -8,6 +8,11 @@ "cs/prep.rkt" "cs/recompile.rkt") +;; Environment variables that affect the build: +;; PLT_BOOTFILE_COMPRESS - enables compression of boot files +;; PLT_CS_MAKE_COMPRESSED_DATA - enables more ".zo" compression +;; PLT_CS_MAKE_NO_COMPRESSED - disables default ".zo" compression + (define-runtime-path here ".") (define scheme-dir (build-path 'up "ChezScheme")) @@ -139,7 +144,8 @@ (parameterize ([current-directory (build-path 'up "cs")]) (define convert.d (build-path build-dir "compiled" "convert.d")) (unless (file-exists? convert.d) (call-with-output-file convert.d void)) - (putenv "PLT_CS_MAKE_COMPRESSED" "yes") + (unless (getenv "PLT_CS_MAKE_NO_COMPRESSED") + (putenv "PLT_CS_MAKE_COMPRESSED" "yes")) (system*! "nmake" (build-path "../build/racket.so") ; need forward slashes (format "RACKET=~a" rel-racket) @@ -220,13 +226,19 @@ args)) (make-directory* "../../lib") -(bootstrap-racket! "../cs/c/embed-boot.rkt" - "++exe" "../build/raw_racketcs.exe" (format "../../Racket~a.exe" cs-suffix) - "++exe" "../build/raw_gracketcs.exe" (format "../../lib/GRacket~a.exe" cs-suffix) - "../build/raw_libracketcs.dll" "../../lib/libracketcsxxxxxxx.dll" - "../build/petite-v.boot" - "../build/scheme-v.boot" - "../build/racket-v.boot") +(apply bootstrap-racket! + "../cs/c/embed-boot.rkt" + (append + (if (getenv "PLT_BOOTFILE_COMPRESS") + '("--compress") + '()) + (list + "++exe" "../build/raw_racketcs.exe" (format "../../Racket~a.exe" cs-suffix) + "++exe" "../build/raw_gracketcs.exe" (format "../../lib/GRacket~a.exe" cs-suffix) + "../build/raw_libracketcs.dll" "../../lib/libracketcsxxxxxxx.dll" + "../build/petite-v.boot" + "../build/scheme-v.boot" + "../build/racket-v.boot"))) (system*! "mt" "-manifest" "racket/racket.manifest"