Skip to content

Commit caaee3c

Browse files
committed
Resolve napi version through Cargo metadata
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
1 parent b39e528 commit caaee3c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

bin/build-native.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@ set -euo pipefail
55
driver_repo=$(pwd)
66
kernel_repo=${DATABRICKS_SQL_KERNEL_REPO:-../../databricks-sql-kernel}
77
napi_dir="${kernel_repo}/napi"
8-
napi_major=$(sed -nE 's/^napi = \{ version = "([0-9]+).*/\1/p' "${napi_dir}/Cargo.toml")
8+
napi_major=$(
9+
cargo metadata --format-version 1 --locked --manifest-path "${napi_dir}/Cargo.toml" |
10+
node -e '
11+
const metadata = JSON.parse(require("fs").readFileSync(0, "utf8"));
12+
const rootId = metadata.resolve.root ?? metadata.workspace_members[0];
13+
const root = metadata.resolve.nodes.find(({ id }) => id === rootId);
14+
const napiId = root?.deps.find(({ name }) => name === "napi")?.pkg;
15+
const version = metadata.packages.find(({ id }) => id === napiId)?.version;
16+
process.stdout.write(version?.split(".")[0] ?? "");
17+
'
18+
)
919

1020
# napi-rs v2 and v3 derive macros expect different CLI environment variables.
1121
case "${napi_major}" in

0 commit comments

Comments
 (0)