forked from sheetjs/docs.sheetjs.com
89 lines
2.3 KiB
Bash
Executable File
89 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# https://docs.sheetjs.com/docs/demos/engines/jsc#swift
|
|
|
|
set -e
|
|
|
|
OS="$(uname -s)"
|
|
ARCH="$(uname -m)"
|
|
|
|
if ! command -v swiftc &>/dev/null; then
|
|
echo "Error: Swift is not installed. Install from https://swift.org/download/"
|
|
exit 1
|
|
fi
|
|
echo "Swift version: $(swiftc --version)"
|
|
|
|
case "$OS" in
|
|
Darwin)
|
|
cd /tmp
|
|
rm -rf sheetjswift
|
|
mkdir -p sheetjswift
|
|
cd sheetjswift
|
|
|
|
curl -sLO https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js
|
|
curl -sLO https://docs.sheetjs.com/pres.numbers
|
|
curl -sLO https://docs.sheetjs.com/swift/SheetJSCore.swift
|
|
curl -sLO https://docs.sheetjs.com/swift/main.swift
|
|
|
|
swiftc SheetJSCore.swift main.swift -o SheetJSwift
|
|
./SheetJSwift pres.numbers
|
|
npx -y xlsx-cli SheetJSwift.xlsx
|
|
;;
|
|
|
|
Linux)
|
|
# This test requires the WebKit build from the C demo
|
|
cd /tmp
|
|
if [ ! -d "sheetjs-jsc" ]; then
|
|
echo "Please run the C demo from https://docs.sheetjs.com/docs/demos/engines/jsc#c"
|
|
exit 1
|
|
fi
|
|
|
|
cd sheetjs-jsc
|
|
if [ ! -d "Release" ]; then
|
|
echo "Please run the C demo from https://docs.sheetjs.com/docs/demos/engines/jsc#c"
|
|
exit 1
|
|
fi
|
|
|
|
rm -rf sheetjswift
|
|
mkdir -p sheetjswift
|
|
cd sheetjswift
|
|
|
|
curl -sLO https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js
|
|
curl -sLO https://docs.sheetjs.com/pres.numbers
|
|
|
|
find ../WebKit/WebKitBuild/JSCOnly/Release/JavaScriptCore/Headers/ -name "*.h" -exec cp {} . \;
|
|
|
|
for f in *.h; do sed -i 's/<JavaScriptCore\//</g' "$f"; done
|
|
|
|
PWD_DIR=$(pwd)
|
|
cat > JavaScriptCore-Bridging-Header.h << EOF
|
|
#import "${PWD_DIR}/JavaScript.h"
|
|
EOF
|
|
|
|
cat > module.modulemap << EOF
|
|
module JavaScriptCore {
|
|
header "./JavaScript.h"
|
|
link "JavaScriptCore"
|
|
}
|
|
EOF
|
|
|
|
curl -sLO https://docs.sheetjs.com/swift/SheetJSCRaw.swift
|
|
|
|
swiftc -Xcc -I$(pwd) \
|
|
-Xlinker -L../WebKit/WebKitBuild/JSCOnly/Release/lib/ \
|
|
-Xlinker -lJavaScriptCore \
|
|
-Xlinker -lWTF \
|
|
-Xlinker -lbmalloc \
|
|
-Xlinker -lstdc++ \
|
|
-Xlinker -latomic \
|
|
-Xlinker -licuuc \
|
|
-Xlinker -licui18n \
|
|
-import-objc-header JavaScriptCore-Bridging-Header.h \
|
|
SheetJSCRaw.swift -o SheetJSwift
|
|
|
|
./SheetJSwift pres.numbers
|
|
npx -y xlsx-cli SheetJSwift.xlsx
|
|
;;
|
|
|
|
*) echo "Unsupported OS: $OS"; exit 1 ;;
|
|
esac
|