forked from maierfelix/nvk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·93 lines (80 loc) · 2.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/// <reference types="./generated/1.1.126/darwin/" />
/// <reference types="./generated/1.1.126/win32/" />
/// <reference types="./generated/1.1.126/linux" />
const fs = require("fs");
const path = require("path");
const pkg = require("./package.json");
function throwInvalidVkVersion() {
process.stderr.write(`Invalid vulkan version specifier!\n`);
throw `Exiting..`;
};
function getVkVersionFromArg(arg) {
let split = arg.split("=");
if (split.length === 2) {
let version = split[1];
if (version.split(".").length !== 3) {
throwInvalidVkVersion();
} else {
return version;
}
} else {
throwInvalidVkVersion();
}
};
// gather vk version
let vkVersion = process.env.npm_config_vkversion;
// attempt npm version
vkVersion = vkVersion || null;
// attempt node argv
if (!vkVersion) {
process.argv.map(arg => {
if (arg.match("vkversion=")) {
vkVersion = getVkVersionFromArg(arg);
}
});
}
if (!vkVersion) vkVersion = pkg.config.POST_DEFAULT_BINDING_VERSION;
// gather disable-validation-checks flag
let disableValidationChecks = process.env.npm_config_disable_validation_checks;
// attempt npm version
disableValidationChecks = disableValidationChecks || null;
// attempt node argv
if (!disableValidationChecks) {
process.argv.map(arg => {
if (arg.match("disable-validation-checks")) {
disableValidationChecks = true;
}
});
}
process.stdout.write(`(nvk) Using Vulkan v${vkVersion}\n`);
let {platform} = process;
// strictly dissallow older versions
if (pkg.config.OUTDATED.indexOf(vkVersion) > -1) {
process.stderr.write(`${vkVersion} is outdated and no longer supported!
Please use v${pkg.config.POST_DEFAULT_BINDING_VERSION} from now on!\n`);
throw `Exiting..`;
}
const releasePath = `${pkg.config.GEN_OUT_DIR}/${vkVersion}/${platform}/build/Release`;
const bindingsPath = path.join(__dirname, `${pkg.config.GEN_OUT_DIR}/`);
const generatedPath = bindingsPath + `${vkVersion}/${platform}`;
// make sure the bindings exist
if (!fs.existsSync(`${generatedPath}/interfaces.js`)) {
process.stderr.write(`(nvk) Failed to load interfaces for v${vkVersion} from ${generatedPath}\n`);
process.stderr.write(`(nvk) Your platform might not be supported\n`);
throw `Exiting..`;
}
if (platform === "darwin") {
// if a vulkan sdk is installed, then make sure that validation layers can be used
if (process.env.hasOwnProperty("VULKAN_SDK")) {
if (!process.env.hasOwnProperty("VK_LAYER_PATH")) {
process.env.VK_LAYER_PATH = path.join(process.env.VULKAN_SDK, `/etc/vulkan/explicit_layer.d`);
}
}
}
if (disableValidationChecks) {
process.stdout.write(`(nvk) Validation checks are disabled\n`);
module.exports = require(`${generatedPath}/interfaces-no-validation.js`);
} else {
process.stdout.write(`(nvk) Validation checks are enabled\n`);
module.exports = require(`${generatedPath}/interfaces.js`);
}