From 220434abdd457596f4026904ea0d149b264551e6 Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 25 Sep 2024 22:13:49 +0000 Subject: [PATCH] Integrate the configure-time Emscripten bits. FossilOrigin-Name: 456125a14454180d608d8f5bc651aa4350958cdd14f4011ef540beb278ca2d51 --- Makefile.in | 7 +- auto.def | 139 ++++++++++++++++++------------------- autosetup/hwaci-common.tcl | 55 +++++++++++++++ manifest | 17 ++--- manifest.uuid | 2 +- tool/emcc.sh.in | 63 +++++++++++++++++ 6 files changed, 201 insertions(+), 82 deletions(-) create mode 100644 tool/emcc.sh.in diff --git a/Makefile.in b/Makefile.in index 8b17ef5e47..687d482915 100644 --- a/Makefile.in +++ b/Makefile.in @@ -14,10 +14,15 @@ # that contains this "Makefile.in" and the "configure" script. # TOP = @abs_top_srcdir@ - # Just testing expansions... +# srcdir = @srcdir@ +# top_srcdir = @top_srcdir@ +# abs_top_srcdir = @abs_top_srcdir@ +# abs_top_builddir = @abs_top_builddir@ # LDFLAGS_ZLIB = @LDFLAGS_ZLIB@ # LDFLAGS_MATH = @LDFLAGS_MATH@ +# LD = @LD@ +# AR = @AR@ # C Compiler and options for use in building executables that # will run on the platform that is doing the build. diff --git a/auto.def b/auto.def index d4ee5fee6a..75c8450e69 100644 --- a/auto.def +++ b/auto.def @@ -1,64 +1,46 @@ # Created by migrate-autoconf - fix items marked XXX global autosetup -use cc cc-shared cc-lib hwaci-common +use cc cc-db cc-shared cc-lib hwaci-common set DUMP_DEFINES_FILE defines.list -set cross_compiling 0 set enable_shared 1 +# Are we cross compiling? +set cross_compiling 0 +if {[get-define host] ne [get-define build]} { + set cross_compiling 1 +} +define cross_compiling ${cross_compiling} + +if {0 && $cross_compiling} { + # gcc's cross-compiler is named platform-os-vendor-gcc instead of + # platform-os-vendor-cc. Checking for cc here will find the CC which + # was already found via (use cc). Checking for gcc here would be + # unportable - the client may well have a different cross-compiler. + define-push {GCC LD AR} { + cc-check-tools gcc ld ar + define BIN_host_GCC [get-define GCC] + define BIN_host_LD [get-define LD] + define BIN_host_AR [get-define AR] + } +} + ######################################################################## -# Note that boolean flags... +# A very long story made short, autosetup's --flag handling has +# some behaviors which make it impossible to implement 100% identical +# flags, compared to the historical autotools build. The differences +# are documented here: # -# 1) Are in the form flagname (default=false) or flagname=0 (false) or -# flagname=1 (true). # -# 2) If they default to false, the actual flag mapped to them is -# --enable-FLAG. +# 1) --debug is used by autosetup itself, so we have to rename it to +# --with-debug. We cannot use --enable-debug because that is, for +# autosetup, and alias for --debug=1. # -# 3) If they default to true, the actual flag mapped to them is -# --disable-FLAG. +# 2) In autosetup, all flags starting with (--enable, --disable) are +# forced to be booleans and received special handling in how they're +# resolved. Because of that we have to rename: # -# 4) For boolean options, configure will accept any of --flag, --enable-flag, -# or --disable-flag. Unfortunately, it reserves --debug for its own use. +# 2.1) --enable-tempstore[=no] to --with-tempstore[=no]. # -# 5) Mapping with their full name, e.g. enable-foo=1 or disable-bar=0, -# will lead to breakage in calls to either [opt-bool foo] or -# [opt-bool enable-foo]. -# -# (2) and (3) mean that the help text for flag=1 should start with -# "Disable" and flag=0 should start with "Enable". -# -# In trying to helpfully map between --foo/--enable-foo/--disable-foo, -# it ends up creating some degree of confusion. -# -# Reminders about flag handling quirks.. -# -# 1) autosetup treats prefixes of 'enable' and 'disable' specially, -# leading to some incompatibilities with the historical sqlite3 -# configure script flags. -# -# Defining non-boolean flags named enable-foo requires different -# downstream handling of those flags. e.g. -# -# enable-tempstore:=no => {...} -# -# requires that [opt-val enable-tempstore], rather than [opt-val -# tempstore], be used, which is in constrast to boolean flags, where -# [opt-bool flag] must be used instead of [opt-bool enable-flag]. -# -# Also, passing --enable-tempstore with no value (to presumably get the -# default value) breaks: autosetup tries to find a boolean-type tempstore -# flag and cannot, so it complains that flag --tempstore is not defined. -# i.e. --enable-tempstore requires that it be passed a value. -# -# An awkward workaround for that, discovered only by random trial and -# error, is to define both {tempstore=1} and {enable-tempstore:}. With -# that in place --enable-tempstore, with no value, works as expected -# (why? Nobody knows!) but --tempstore can only ever be legally passed -# a boolean value (0, 1, yes, no, enabled, disabled). It does, -# however, pollute the --help with a synthetic --disable-tempstore -# option. After an hour of fighting with it, a switch from -# --enable-tempstore to --with-tempstore seems like the better -# approach, in that it doesn't lead to a losing fight with autosetup. options { with-debug:=1 => {Enable debug build flags} with-tclsh:PATHNAME => {Full pathname of tclsh to use} @@ -95,16 +77,21 @@ options { with-emsdk:DIR => {Top-most dir of the Emscripten SDK installation} dump-defines=1 => {Dump autosetup defines to $DUMP_DEFINES_FILE} } -# debug=0 => {debugging & verbose explain} set srcdir $autosetup(srcdir) -puts "srcdir = $srcdir" -set VERSION [readfile $srcdir/VERSION] +#puts "srcdir = $srcdir" +set VERSION [readfile $autosetup(srcdir)/VERSION] puts "VERSION = $VERSION" define PACKAGE_VERSION $VERSION #puts "with-wasi-sdk? = [opt-val with-wasi-sdk]" #puts "with-debug? = [opt-val with-debug]" +set outOfTreeBuild 0 +if {![file exists sqlite3.pc.in]} { + puts "This appears to be an out-of-tree build." + set outOfTreeBuild 1 +} + # # The build process allows for using a cross-compiler. But the default # action is to target the same platform that we are running on. The @@ -281,6 +268,7 @@ undefine lib_fdatasync # Check for needed/wanted headers cc-check-includes sys/types.h stdlib.h stdint.h inttypes.h malloc.h if {[cc-check-includes zlib.h] && [cc-check-function-in-lib deflate z]} { + # TODO: port over the more sophisticated zlib search from the fossil auto.def define HAVE_ZLIB 1; # "-DSQLITE_HAVE_ZLIB=1" define LDFLAGS_ZLIB -lz } else { @@ -289,9 +277,13 @@ if {[cc-check-includes zlib.h] && [cc-check-function-in-lib deflate z]} { } hwaci-define-if-opt-truthy with-debug SQLITE_DEBUG "Debug build?" -hwaci-define-if-opt-truthy amalgamation USE_AMALGAMATION "Use amalgamation for builds?" +hwaci-define-if-opt-truthy amalgamation USE_AMALGAMATION \ + "Use amalgamation for builds?" hwaci-define-if-opt-truthy gcov USE_GCOV "Use gcov?" -hwaci-define-if-opt-truthy test-status TSTRNNR_OPTS "test-runner flags?" {--status} {} +hwaci-define-if-opt-truthy test-status TSTRNNR_OPTS \ + "test-runner flags:" {--status} {} +hwaci-define-if-opt-truthy linemacros AMALGAMATION_LINE_MACROS \ + "Use #line macros in the amalgamation:" {--linemacros=1} {--linemacros=0} if {0} { ######### @@ -685,6 +677,20 @@ if {0} { # XXX BUILD_CFLAGS=$ac_temp_BUILD_CFLAGS } +########## +# Emscripten SDK for building the web-based wasm components. +# +if {[hwaci-check-emsdk]} { + set wrapper $srcdir/tool/emcc.sh + define EMCC_WRAPPER $wrapper + hwaci-make-from-dot-in $wrapper 1 + catch {exec chmod u+x $wrapper} + unset wrapper +} else { + define EMCC_WRAPPER "" + catch {exec rm -f $srcdir/tool/emcc.sh} +} + proc affirm-have-math {} { if {![cc-check-function-in-lib log m]} { user-error "Missing required math APIs" @@ -726,23 +732,6 @@ foreach {boolFlag featureFlag ifSetEvalThis} { } } -msg-checking "Use #line macros in the amalgamation: " -hwaci-if-opt-truthy linemacros { - define AMALGAMATION_LINE_MACROS {--linemacros=1} - msg-result yes -} { - define AMALGAMATION_LINE_MACROS {--linemacros=0} - msg-result no -} - - -########## -# Emscripten SDK -# -if {1} { - # TODO: port this bit and its associated shell script from the - # Fossil source tree's auto.def and tools/emcc.sh.in. -} ######### # Generate the output files. @@ -776,7 +765,13 @@ hwaci-if-opt-truthy dump-defines { msg-result "--dump-defines is creating file: $DUMP_DEFINES_FILE" make-config-header $DUMP_DEFINES_FILE \ -bare {OPT_FEATURE_FLAGS SQLITE_OS* SQLITE_DEBUG LDFLAGS_* USE_*} \ + -str {BIN_* CC LD AR} \ -auto {*} # achtung: ^^^^ whichever SQLITE_OS_foo flag which is set to 0 will # get _undefined_ here unless it's part of the -bare set. + if {0} { + foreach x $::define { + puts "\t$x" + } + } } diff --git a/autosetup/hwaci-common.tcl b/autosetup/hwaci-common.tcl index 20bdb4b470..8466e0116d 100644 --- a/autosetup/hwaci-common.tcl +++ b/autosetup/hwaci-common.tcl @@ -428,3 +428,58 @@ proc hwaci-check-exeext {} { msg-result no } } + +######################################################################## +# Emscripten is used for doing in-tree builds of web-based WASM stuff, +# as opposed to WASI-based WASM or WASM binaries we import from other +# places. This is only set up for Unix-style OSes and is untested +# anywhere but Linux. +# +# Defines the following: +# +# - EMSDK_HOME = top dir of the emsdk or "". It looks for +# --with-emsdk=DIR or the $EMSDK environment variable. +# - EMSDK_ENV = path to EMSDK_HOME/emsdk_env.sh or "" +# - BIN_EMCC = $EMSDK_HOME/upstream/emscripten/emcc or "" +# +# Returns 1 if EMSDK_ENV is found, else 0. If EMSDK_HOME is not empty +# but BIN_EMCC is then emcc was not found in the EMSDK_HOME, in which +# case we have to rely on the fact that sourcing $EMSDK_ENV from a +# shell will add emcc to the $PATH. +proc hwaci-check-emsdk {} { + set emsdkHome [opt-val with-emsdk] + define EMSDK_HOME "" + define EMSDK_ENV "" + define BIN_EMCC "" +# define EMCC_OPT "-Oz" + msg-checking "Emscripten SDK? " + if {$emsdkHome eq "" && [info exists ::env(EMSDK)]} { + # Fall back to checking the environment. $EMSDK gets set + # by sourcing emsdk_env.sh. + set emsdkHome $::env(EMSDK) + } + set rc 0 + if {$emsdkHome ne ""} { + define EMSDK_HOME $emsdkHome + set emsdkEnv "$emsdkHome/emsdk_env.sh" + if {[file exists $emsdkEnv]} { + msg-result "$emsdkHome" + define EMSDK_ENV $emsdkEnv +# if {[info exists ::env(EMCC_OPT)]} { +# define EMCC_OPT $::env(EMCC_OPT) +# } + set rc 1 + set emcc "$emsdkHome/upstream/emscripten/emcc" + if {[file exists $emcc]} { + # puts "is emcc == $emcc ???" + define BIN_EMCC $emcc + } + } else { + msg-result "emsdk_env.sh not found in $emsdkHome" + } + } else { + msg-result "not found" + } + define HAVE_EMSDK $rc + return $rc +} diff --git a/manifest b/manifest index c124584a49..27e3304a7c 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Further\sstreamlining\sof\sauto.def. -D 2024-09-25T18:03:26.242 +C Integrate\sthe\sconfigure-time\sEmscripten\sbits. +D 2024-09-25T22:13:49.969 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 -F Makefile.in 7b3bc24530c2a6580d4b3a049a3f45246118fa2098ce5dd10ab76333f02f7246 +F Makefile.in 423f8b90ccb385a96c9f9551d74ab2b678e7a6191bf908c2b44304997804cb63 F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 F Makefile.msc e3c4723c27464acc31da4420b808c8d2690180ba2b915897bece0a9d5d2cecf6 F README.md c3c0f19532ce28f6297a71870f3c7b424729f0e6d9ab889616d3587dd2332159 @@ -14,7 +14,7 @@ F art/icon-80x90.gif 65509ce3e5f86a9cd64fe7fca2d23954199f31fe44c1e09e208c80fb83d F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 -F auto.def 334d1bcda82fe05ac65baa1485701e05911ce4304175f716bacc33b5ddb1d61c +F auto.def 25c1a8645d4845bc2970d183be0ac2c9bdf0f05c348fc6705385c17047802bb4 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am adedc1324b6a87fdd1265ddd336d2fb7d4f36a0e77b86ea553ae7cc4ea239347 F autoconf/Makefile.fallback 22fe523eb36dfce31e0f6349f782eb084e86a5620b2b0b4f84a2d6133f53f5ac @@ -46,7 +46,7 @@ F autosetup/cc-lib.tcl 493c5935b5dd3bf9bd4eca89b07c8b1b1a9356d61783035144e21795f F autosetup/cc-shared.tcl 4f024e94a47f427ba61de1739f6381ef0080210f9fae89112d5c1de1e5460d78 F autosetup/cc.tcl 1b52de228642c1db5a714d54ca974d723ec8b4092e8c3765d348b625850f7311 F autosetup/default.auto 5cdf016de2140e50f1db190a02039dc42fb390af1dda4cc4853e3042a9ef0e82 -F autosetup/hwaci-common.tcl 6c48b16beb9eb8015f207980095f5f65c55e5238159a9d50791b643e5c295205 +F autosetup/hwaci-common.tcl c0ff4bb3399f7a55b5dba83ab6f98b68a54952f28ae49c658340b48ea3cd827d F autosetup/jimsh0.c 1b5fe91fffcddbc29f2b16acb80f1650632ea2edbe8336b8155ef7b4c66f6d8d F autosetup/pkg-config.tcl 4e635bf39022ff65e0d5434339dd41503ea48fc53822c9c5bde88b02d3d952ba F autosetup/system.tcl 3a39d6e0b3bfba526fd39afe07c1d0d325e5a31925013a1ba7c671e1128e31bb @@ -2130,6 +2130,7 @@ F tool/custom.txt 6cdf298f43e1db4bb91406d14777669b8fb1df790837823fa6754c4308decc F tool/dbhash.c 5da0c61032d23d74f2ab84ffc5740f0e8abec94f2c45c0b4306be7eb3ae96df0 F tool/dbtotxt.c ca48d34eaca6d6b6e4bd6a7be2b72caf34475869054240244c60fa7e69a518d6 F tool/dbtotxt.md c9a57af8739957ef36d2cfad5c4b1443ff3688ed33e4901ee200c8b651f43f3c +F tool/emcc.sh.in bc3f3a29f5a7272afe605a483d6463617f27d31c74fa9135c7eaa3b844345b74 F tool/enlargedb.c 3e8b2612b985cfa7e3e8800031ee191b43ae80de96abb5abbd5eada62651ee21 F tool/extract-sqlite3h.tcl 069ceab0cee26cba99952bfa08c0b23e35941c837acabe143f0c355d96c9e2eb x F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 @@ -2232,8 +2233,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8716c35eaa168677a10de7b4aa55d35c54035f5e685cc1a5890b940a41cc6ff7 -R 7ae842c7d3995cad59964f0358f0039c +P 74d12433599e2f189d8d0a44be834651531ac5a215bf42de386053cd00d29162 +R dd47ba23be16ca7a64fc24efb04f8a5b U stephan -Z fd55233750e1823126fedbcf310025fa +Z 7445a300c3d8549aa733ba93da0d5f2b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 172f049785..adaa3beb74 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -74d12433599e2f189d8d0a44be834651531ac5a215bf42de386053cd00d29162 +456125a14454180d608d8f5bc651aa4350958cdd14f4011ef540beb278ca2d51 diff --git a/tool/emcc.sh.in b/tool/emcc.sh.in new file mode 100644 index 0000000000..91ed6a2c27 --- /dev/null +++ b/tool/emcc.sh.in @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +######################################################################## +# WARNING: emcc.sh is generated from emcc.sh.in by the configure +# process. Do not edit emcc.sh directly, as it may be deleted or +# overwritten by the configure script. +# +# A wrapper around the emcc compiler which uses configure-time state +# to locate the Emscripten SDK and import the SDK's environment +# script, if needed. +######################################################################## +# EMSDK_HOME comes from the configure --with-emsdk=/dir flag. +# EMSDK_ENV is ${thatDir}/emsdk_env.sh and is also set by the +# configure process. +EMSDK_HOME="@EMSDK_HOME@" +EMSDK_ENV="@EMSDK_ENV@" +emcc="@BIN_EMCC@" + +if [x = "x${emcc}" ]; then + emcc=$(which emcc 2>/dev/null) +fi + +if [ x = "x${emcc}" ]; then + # If emcc is not found in the path, try to find it via an emsdk + # installation. The SDK variant is the official installation + # style supported by the Emscripten folks, but emcc is also + # available via package managers on some OSes. + if [ x = "x${EMSDK_HOME}" ]; then + echo "EMSDK_HOME is not set. Pass --with-emsdk=/path/to/emsdk" \ + "to the configure script." 1>&2 + exit 1 + fi + + if [ x = "x${EMSDK_ENV}" ]; then + if [ -f "${EMSDK_HOME}/emsdk_env.sh" ]; then + EMSDK_ENV="${EMSDK_HOME}/emsdk_env.sh" + else + echo "EMSDK_ENV is not set. Expecting configure script to set it." 1>&2 + exit 2 + fi + fi + + if [ ! -f "${EMSDK_ENV}" ]; then + echo "emsdk_env script not found: $EMSDK_ENV" 1>&2 + exit 3 + fi + + # $EMSDK is part of the state set by emsdk_env.sh. + if [ x = "x${EMSDK}" ]; then + source "${EMSDK_ENV}" >/dev/null 2>&1 || { + # ^^^ unfortunately outputs lots of noise to stderr + rc=$? + echo "Error sourcing ${EMSDK_ENV}" + exit $rc + } + fi + emcc=$(which emcc 2>/dev/null) + if [ x = "x${emcc}" ]; then + echo "emcc not found in PATH. Normally that's set up by EMSDK_ENV." 1>&2 + exit 4 + fi +fi + +exec emcc "$@"