Revert "typescript bindings maintenance (#2363)"

As discussed on Discord, this PR was not ready to be merged. CI fails on
it.

This reverts commit a602f7fde7.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel
2024-06-03 17:25:28 -04:00
parent a602f7fde7
commit 55d709862f
30 changed files with 876 additions and 1115 deletions

View File

@@ -1,47 +0,0 @@
const fs = require("fs");
const path = require("path");
// Copies the shared llmodel sources from gpt4all-backend into the backend folder.
// These are dependencies of the bindings and will be required in case node-gyp-build
// cannot find a prebuild. This script is used in the package install hook and will
// be executed BOTH when `yarn install` is run in the root folder AND when the package
// is installed as a dependency in another project.
const backendDeps = [
"llmodel.h",
"llmodel.cpp",
"llmodel_c.cpp",
"llmodel_c.h",
"sysinfo.h",
"dlhandle.h",
"dlhandle.cpp",
];
const sourcePath = path.resolve(__dirname, "../../../gpt4all-backend");
const destPath = path.resolve(__dirname, "../backend");
// Silently ignore if the backend sources are not available.
// When the package is installed as a dependency, gpt4all-backend will not be present.
if (fs.existsSync(sourcePath)) {
if (!fs.existsSync(destPath)) {
fs.mkdirSync(destPath);
}
for (const file of backendDeps) {
const sourceFile = path.join(sourcePath, file);
const destFile = path.join(destPath, file);
if (fs.existsSync(sourceFile)) {
console.info(`Copying ${sourceFile} to ${destFile}`);
fs.copyFileSync(sourceFile, destFile); // overwrite
} else {
throw new Error(`File ${sourceFile} does not exist`);
}
}
}
// assert that the backend sources are present
for (const file of backendDeps) {
const destFile = path.join(destPath, file);
if (!fs.existsSync(destFile)) {
throw new Error(`File ${destFile} does not exist`);
}
}

View File

@@ -1,42 +1,12 @@
#!/bin/sh
# Build script for Unix-like systems (Linux, macOS).
# Script assumes the current working directory is the bindings project root.
SYSNAME=$(uname -s)
PLATFORM=$(uname -m)
# Allows overriding target sysname and platform via args
# If not provided, the current system's sysname and platform will be used
while [ $# -gt 0 ]; do
case "$1" in
--sysname=*)
SYSNAME="${1#*=}"
shift
;;
--platform=*)
PLATFORM="${1#*=}"
shift
;;
*)
echo "Unknown argument: $1" >&2
exit 1
;;
esac
done
if [ "$SYSNAME" = "Linux" ]; then
if [ "$PLATFORM" = "x86_64" ]; then
BASE_DIR="runtimes/linux-x64"
elif [ "$PLATFORM" = "aarch64" ]; then
BASE_DIR="runtimes/linux-arm64"
else
echo "Unsupported platform: $PLATFORM" >&2
exit 1
fi
BASE_DIR="runtimes/linux-x64"
LIB_EXT="so"
elif [ "$SYSNAME" = "Darwin" ]; then
BASE_DIR="runtimes/darwin"
BASE_DIR="runtimes/osx"
LIB_EXT="dylib"
elif [ -n "$SYSNAME" ]; then
echo "Unsupported system: $SYSNAME" >&2
@@ -52,24 +22,8 @@ BUILD_DIR="$BASE_DIR/build"
rm -rf "$BASE_DIR"
mkdir -p "$NATIVE_DIR" "$BUILD_DIR"
if [ "$PLATFORM" = "x86_64" ]; then
echo "Building for x86_64"
cmake -S ../../gpt4all-backend -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=RelWithDebInfo
fi
if [ "$PLATFORM" = "aarch64" ]; then
if [ "$(uname -m)" != "aarch64" ]; then
echo "Cross-compiling for aarch64"
cmake -S ../../gpt4all-backend \
-B "$BUILD_DIR" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_TOOLCHAIN_FILE="./toolchains/linux-arm64-toolchain.cmake"
else
cmake -S ../../gpt4all-backend -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=RelWithDebInfo
fi
fi
cmake --build "$BUILD_DIR" --parallel && {
cmake -S ../../gpt4all-backend -B "$BUILD_DIR" &&
cmake --build "$BUILD_DIR" -j --config Release && {
cp "$BUILD_DIR"/libgptj*.$LIB_EXT "$NATIVE_DIR"/
cp "$BUILD_DIR"/libllama*.$LIB_EXT "$NATIVE_DIR"/
}
}

View File

@@ -1,21 +1,22 @@
const prebuildify = require("prebuildify");
async function createPrebuilds(configs) {
for (const config of configs) {
async function createPrebuilds(combinations) {
for (const { platform, arch } of combinations) {
const opts = {
platform,
arch,
napi: true,
targets: ["18.16.0"],
...config,
targets: ["18.16.0"]
};
try {
await createPrebuild(opts);
console.log(
`Build succeeded for platform ${opts.platform} and architecture ${opts.arch}`,
`Build succeeded for platform ${opts.platform} and architecture ${opts.arch}`
);
} catch (err) {
console.error(
`Error building for platform ${opts.platform} and architecture ${opts.arch}:`,
err,
err
);
}
}
@@ -23,17 +24,6 @@ async function createPrebuilds(configs) {
function createPrebuild(opts) {
return new Promise((resolve, reject) => {
// if this prebuild is cross-compiling for arm64 on a non-arm64 machine,
// set the CXX and CC environment variables to the cross-compilers
if (
opts.arch === "arm64" &&
process.arch !== "arm64" &&
process.platform === "linux"
) {
process.env.CXX = "aarch64-linux-gnu-g++-12";
process.env.CC = "aarch64-linux-gnu-gcc-12";
}
prebuildify(opts, (err) => {
if (err) {
reject(err);
@@ -45,18 +35,22 @@ function createPrebuild(opts) {
}
let prebuildConfigs;
if (process.platform === "win32") {
prebuildConfigs = [{ platform: "win32", arch: "x64" }];
} else if (process.platform === "linux") {
if(process.platform === 'win32') {
prebuildConfigs = [
{ platform: "win32", arch: "x64" }
];
} else if(process.platform === 'linux') {
//Unsure if darwin works, need mac tester!
prebuildConfigs = [
{ platform: "linux", arch: "x64" },
//{ platform: "linux", arch: "arm64" },
//{ platform: "linux", arch: "armv7" },
]
} else if(process.platform === 'darwin') {
prebuildConfigs = [
{ platform: "linux", arch: "x64" },
{ platform: "linux", arch: "arm64" },
];
} else if (process.platform === "darwin") {
prebuildConfigs = [
{ platform: "darwin", arch: "x64" },
{ platform: "darwin", arch: "arm64" },
];
{ platform: "darwin", arch: "x64" },
{ platform: "darwin", arch: "arm64" },
]
}
createPrebuilds(prebuildConfigs)