@@ -62,28 +62,39 @@ if [ -z "${TSLANG_LIB_PATH}" ]; then
6262 export TSLANG_LIB_PATH=$BUILD_PATH /$TOOL_NAME /ninja/$BUILD /lib
6363fi
6464
65- rm -rf dll/$BUILD /$MM lib/$BUILD /$MM
66- mkdir -p dll/$BUILD /$MM
67- mkdir -p lib/$BUILD /$MM
68- $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/io.cpp -o $OUTPUT /lib/$BUILD /$MM /io.o
69- $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/datetime.cpp -o $OUTPUT /lib/$BUILD /$MM /datetime.o
70- $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/regex.cpp -o $OUTPUT /lib/$BUILD /$MM /regex.o
71- $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/thread.cpp -o $OUTPUT /lib/$BUILD /$MM /thread.o
72- $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/http_linux.cpp -o $OUTPUT /lib/$BUILD /$MM /http_linux.o
73- $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/memory.cpp -o $OUTPUT /lib/$BUILD /$MM /memory.o
74-
75- $BIN_PATH /$TOOL_NAME $DBG_OPTS $MM_OPT --emit=obj --export=none --nowarn --no-default-lib $SRC /src/lib.linux.ts $PIC -o $OUTPUT /lib/$BUILD /$MM /lib.linux.o
65+ # The output folders, from tslang itself (--print-default-lib-dir), with the same build and model
66+ # flags it compiles with below: defaultlib/{lib,dll}/<arch>/<vendor>/<os>/<env>/<build>/<model>, composed
67+ # the way tslang later looks the library up (see tslang/include/TypeScript/Defines.h). Spelled out
68+ # here, the two would drift apart.
69+ LIB_OUT=$( $BIN_PATH /$TOOL_NAME --print-default-lib-dir=lib $DBG_OPTS $MM_OPT )
70+ DLL_OUT=$( $BIN_PATH /$TOOL_NAME --print-default-lib-dir=dll $DBG_OPTS $MM_OPT )
71+ if [ -z " $LIB_OUT " ] || [ -z " $DLL_OUT " ] ; then
72+ echo " $BIN_PATH /$TOOL_NAME cannot name the output folders (--print-default-lib-dir): it predates the per-target layout, or is missing"
73+ exit 1
74+ fi
75+
76+ rm -rf $DLL_OUT $LIB_OUT
77+ mkdir -p $DLL_OUT
78+ mkdir -p $LIB_OUT
79+ $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/io.cpp -o $OUTPUT /$LIB_OUT /io.o
80+ $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/datetime.cpp -o $OUTPUT /$LIB_OUT /datetime.o
81+ $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/regex.cpp -o $OUTPUT /$LIB_OUT /regex.o
82+ $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/thread.cpp -o $OUTPUT /$LIB_OUT /thread.o
83+ $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/http_linux.cpp -o $OUTPUT /$LIB_OUT /http_linux.o
84+ $TOOL $DBG_GCC $CPP_FLAGS -c $SRC /src/wrappers/memory.cpp -o $OUTPUT /$LIB_OUT /memory.o
85+
86+ $BIN_PATH /$TOOL_NAME $DBG_OPTS $MM_OPT --emit=obj --export=none --nowarn --no-default-lib $SRC /src/lib.linux.ts $PIC -o $OUTPUT /$LIB_OUT /lib.linux.o
7687
7788# Build Lib
78- $BIN_PATH /$TOOL_NAME $DBG_OPTS $MM_OPT --emit=obj --export=none --nowarn --no-default-lib $SRC /src/lib.ts $PIC -o $OUTPUT /lib/ $BUILD / $MM /lib.o
79- $ARC rcs $OUTPUT /lib/ $BUILD / $MM / libTypeScriptDefaultLibCore.a $OUTPUT /lib/ $BUILD / $MM / lib.o $OUTPUT /lib/ $BUILD / $MM / lib.linux.o $OUTPUT /lib/ $BUILD / $MM / io.o $OUTPUT /lib/ $BUILD / $MM / datetime.o $OUTPUT /lib/ $BUILD / $MM / regex.o $OUTPUT /lib/ $BUILD / $MM / thread.o $OUTPUT /lib/ $BUILD / $MM / http_linux.o $OUTPUT /lib/ $BUILD / $MM /memory.o
89+ $BIN_PATH /$TOOL_NAME $DBG_OPTS $MM_OPT --emit=obj --export=none --nowarn --no-default-lib $SRC /src/lib.ts $PIC -o $OUTPUT /$LIB_OUT /lib.o
90+ $ARC rcs $OUTPUT /$LIB_OUT / libTypeScriptDefaultLibCore.a $OUTPUT /$LIB_OUT / lib.o $OUTPUT /$LIB_OUT / lib.linux.o $OUTPUT /$LIB_OUT / io.o $OUTPUT /$LIB_OUT / datetime.o $OUTPUT /$LIB_OUT / regex.o $OUTPUT /$LIB_OUT / thread.o $OUTPUT /$LIB_OUT / http_linux.o $OUTPUT /$LIB_OUT /memory.o
8091
8192# A static archive cannot record its own dependencies on ELF (there is no ld.bfd equivalent of
8293# the `#pragma comment(lib, ...)` http.cpp uses on Windows), so programs linking
8394# -lTypeScriptDefaultLib failed with undefined curl_* references. libTypeScriptDefaultLib.a is
8495# therefore a GNU linker script (as glibc's libc.so is) that pulls in the real archive plus the
8596# system libraries it needs. The compiler keeps passing -lTypeScriptDefaultLib unchanged.
86- cat > $OUTPUT /lib/ $BUILD / $MM /libTypeScriptDefaultLib.a << EOF
97+ cat > $OUTPUT /$LIB_OUT /libTypeScriptDefaultLib.a << EOF
8798/* GNU ld script: TypeScriptDefaultLib and its external dependencies */
8899INPUT(-lTypeScriptDefaultLibCore -lcurl)
89100EOF
94105# undefined on purpose: they must bind to the one collector already in the process
95106# (libTypeScriptRuntime.so under the JIT, libgc.a in an exe); linking libgc.a in here would
96107# give the library a second, separate heap.
97- g++ -shared $DBG_GCC $OUTPUT /lib/ $BUILD / $MM / lib.o $OUTPUT /lib/ $BUILD / $MM / lib.linux.o $OUTPUT /lib/ $BUILD / $MM / io.o $OUTPUT /lib/ $BUILD / $MM / datetime.o $OUTPUT /lib/ $BUILD / $MM / regex.o $OUTPUT /lib/ $BUILD / $MM / thread.o $OUTPUT /lib/ $BUILD / $MM / http_linux.o $OUTPUT /lib/ $BUILD / $MM / memory.o -lcurl -lm -o $OUTPUT /dll/ $BUILD / $MM /libTypeScriptDefaultLib.so
108+ g++ -shared $DBG_GCC $OUTPUT /$LIB_OUT / lib.o $OUTPUT /$LIB_OUT / lib.linux.o $OUTPUT /$LIB_OUT / io.o $OUTPUT /$LIB_OUT / datetime.o $OUTPUT /$LIB_OUT / regex.o $OUTPUT /$LIB_OUT / thread.o $OUTPUT /$LIB_OUT / http_linux.o $OUTPUT /$LIB_OUT / memory.o -lcurl -lm -o $OUTPUT /$DLL_OUT /libTypeScriptDefaultLib.so
98109
99110# Copy
100- # Stage into a single shared defaultlib tree with per-build subfolders under dll/ and lib/,
101- # each holding one subfolder per memory model. Only the current build's subfolders are
102- # refreshed, and they are refreshed from the source tree, so the other mode (debug/release)
103- # staged by a separate run is preserved and so are the models staged by earlier runs of this
104- # one - only this run's model was removed from the source tree above.
105- BUILD_LIB_PATH=./__build/defaultlib/
106- rm -rf $BUILD_LIB_PATH /dll/$BUILD /$MM $BUILD_LIB_PATH /lib/$BUILD /$MM
107- mkdir -p $BUILD_LIB_PATH /dll/$BUILD /$MM
108- mkdir -p $BUILD_LIB_PATH /lib/$BUILD /$MM
111+ # Stage into a single shared defaultlib tree with per-target, per-build and per-model subfolders
112+ # under dll/ and lib/. Only the current build's subfolders are refreshed, and they are refreshed
113+ # from the source tree, so the other targets and modes (debug/release) staged by separate runs are
114+ # preserved and so are the models staged by earlier runs of this one - only this run's model was
115+ # removed from the source tree above. LIB_OUT/DLL_OUT start with defaultlib/, so they go under
116+ # STAGE_PATH; the declarations go to its defaultlib/ root, shared by every build.
117+ STAGE_PATH=./__build
118+ BUILD_LIB_PATH=$STAGE_PATH /defaultlib/
119+ rm -rf $STAGE_PATH /$DLL_OUT $STAGE_PATH /$LIB_OUT
120+ mkdir -p $STAGE_PATH /$DLL_OUT
121+ mkdir -p $STAGE_PATH /$LIB_OUT
109122
110123# Record which compiler built this library, so a mismatch (e.g. after an ABI or
111124# codegen change in tslang) can be diagnosed from the artifact alone.
112125$BIN_PATH /$TOOL_NAME --version > $BUILD_LIB_PATH /COMPILER_VERSION.txt 2>&1
113126
114127# cleanup intermediate object files
115- rm $OUTPUT /lib/ $BUILD / $MM /* .o
128+ rm $OUTPUT /$LIB_OUT /* .o
116129
117- cp -r $SRC /dll/ $BUILD / $MM / * $BUILD_LIB_PATH /dll/ $BUILD / $MM /
118- cp -r $SRC /lib/ $BUILD / $MM / * $BUILD_LIB_PATH /lib/ $BUILD / $MM /
130+ cp -r $SRC /$DLL_OUT / * $STAGE_PATH / $DLL_OUT /
131+ cp -r $SRC /$LIB_OUT / * $STAGE_PATH / $LIB_OUT /
119132cp -r $SRC /src/* $BUILD_LIB_PATH
0 commit comments