@titanpl/core 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configure.js +42 -24
- package/package.json +1 -1
package/configure.js
CHANGED
|
@@ -2,48 +2,66 @@ import { readFileSync, existsSync, writeFileSync } from 'fs';
|
|
|
2
2
|
import { resolve, dirname } from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { platform as _platform } from 'os';
|
|
5
|
+
import { spawnSync } from 'child_process';
|
|
5
6
|
|
|
6
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
8
|
const __dirname = dirname(__filename);
|
|
8
|
-
const platform = _platform();
|
|
9
|
+
const platform = _platform();
|
|
9
10
|
const titanConfigPath = resolve(__dirname, 'titan.json');
|
|
10
11
|
|
|
11
12
|
console.log(`Configuring titan.json for platform: ${platform}`);
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// 1. Platform-specific output file name
|
|
15
|
+
let libFile = "";
|
|
16
|
+
if (platform === "win32") {
|
|
17
|
+
libFile = "titan_core.dll";
|
|
18
|
+
} else if (platform === "darwin") {
|
|
19
|
+
libFile = "libtitan_core.dylib";
|
|
20
|
+
} else {
|
|
21
|
+
libFile = "libtitan_core.so";
|
|
22
|
+
}
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
libPath = "native/target/release/titan_core.dll";
|
|
20
|
-
} else if (platform === 'darwin') {
|
|
21
|
-
libPath = "native/target/release/libtitan_core.dylib";
|
|
22
|
-
} else {
|
|
23
|
-
// Assume linux/unix defaults for anything else
|
|
24
|
-
libPath = "native/target/release/libtitan_core.so";
|
|
25
|
-
}
|
|
24
|
+
const nativeDir = resolve(__dirname, "native");
|
|
25
|
+
const expectedBinary = resolve(nativeDir, "target/release", libFile);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
// 2. Build if binary missing
|
|
28
|
+
if (!existsSync(expectedBinary)) {
|
|
29
|
+
console.log(`Native binary missing. Building silently for ${platform}...`);
|
|
30
|
+
|
|
31
|
+
const build = spawnSync(
|
|
32
|
+
"cargo",
|
|
33
|
+
["build", "--release"],
|
|
34
|
+
{
|
|
35
|
+
cwd: nativeDir,
|
|
36
|
+
stdio: "ignore", // <-- completely hides Rust logs
|
|
37
|
+
shell: true
|
|
38
|
+
}
|
|
39
|
+
);
|
|
31
40
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
process.exit(0);
|
|
41
|
+
if (build.status !== 0) {
|
|
42
|
+
console.error("Cargo build failed. (No logs shown due to silent mode)");
|
|
43
|
+
process.exit(1);
|
|
36
44
|
}
|
|
37
45
|
|
|
46
|
+
console.log(`Build completed for ${platform}.`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 3. Update titan.json
|
|
50
|
+
try {
|
|
51
|
+
const content = readFileSync(titanConfigPath, "utf8");
|
|
52
|
+
const titanConfig = JSON.parse(content);
|
|
53
|
+
|
|
54
|
+
const relativeLibPath = `native/target/release/${libFile}`;
|
|
55
|
+
|
|
38
56
|
if (!titanConfig.native) {
|
|
39
57
|
titanConfig.native = {};
|
|
40
58
|
}
|
|
41
59
|
|
|
42
|
-
titanConfig.native.path =
|
|
60
|
+
titanConfig.native.path = relativeLibPath;
|
|
43
61
|
|
|
44
62
|
writeFileSync(titanConfigPath, JSON.stringify(titanConfig, null, 2));
|
|
45
|
-
console.log(`
|
|
63
|
+
console.log(`Updated titan.json to use native binary: ${relativeLibPath}`);
|
|
46
64
|
} catch (error) {
|
|
47
|
-
console.error("Error
|
|
65
|
+
console.error("Error updating titan.json:", error);
|
|
48
66
|
process.exit(1);
|
|
49
67
|
}
|
package/package.json
CHANGED