@ihason/rust-portable-linux-arm64 0.0.0-placeholder → 1.100.0
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/README.md +31 -0
- package/archive.json +21 -0
- package/extract.js +222 -0
- package/install.js +137 -0
- package/package.json +45 -1
- package/setup.js +566 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @ihason/rust-portable-linux-arm64
|
|
2
|
+
|
|
3
|
+
Portable Rust 1.100.0 toolchain for Linux arm64.
|
|
4
|
+
|
|
5
|
+
Install the entry package and run the setup command:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @ihason/rust-portable setup
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The setup command is interactive. It asks for the install location, PATH
|
|
12
|
+
configuration and self-check. Press Enter to accept the recommended values.
|
|
13
|
+
|
|
14
|
+
All data comes from the npm chunk packages. Setup does not use GitHub.
|
|
15
|
+
|
|
16
|
+
This platform package does not download anything from the network. It joins
|
|
17
|
+
the data chunks, verifies the SHA256, and extracts the archive.
|
|
18
|
+
|
|
19
|
+
After setup:
|
|
20
|
+
|
|
21
|
+
1. Run `bash <extracted>/linux/install.sh`.
|
|
22
|
+
2. Open a new terminal, or source `env.sh`.
|
|
23
|
+
3. Run `<prefix>/share/rust-portable/doctor.sh`.
|
|
24
|
+
|
|
25
|
+
If you run `npm install` instead, the postinstall script extracts the bundle
|
|
26
|
+
to `rust-portable` in the directory where npm was run. Run `install.sh` on
|
|
27
|
+
Linux after extraction.
|
|
28
|
+
|
|
29
|
+
The bundle contains third-party toolchains with their own licenses. See
|
|
30
|
+
`shared/licenses/` and `shared/THIRD-PARTY-NOTICES.md` in the installed bundle.
|
|
31
|
+
Documentation: <https://github.com/HasonHuang/rust-portable/blob/main/docs/NPM.md>
|
package/archive.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"platform": "linux-arm64",
|
|
3
|
+
"asset": "rust-portable-v1.100.0-linux-arm64.tar.gz",
|
|
4
|
+
"type": "tar.gz",
|
|
5
|
+
"bundleVersion": "1.100.0",
|
|
6
|
+
"bundleRevision": "",
|
|
7
|
+
"size": 132769557,
|
|
8
|
+
"sha256": "eccb2b249a73e7c6c00a105643eaa3e96d5f50daec65045810089603ee82905e",
|
|
9
|
+
"parts": [
|
|
10
|
+
{
|
|
11
|
+
"package": "@ihason/rust-portable-linux-arm64-chunk-01",
|
|
12
|
+
"file": "part01",
|
|
13
|
+
"bytes": 104857600
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"package": "@ihason/rust-portable-linux-arm64-chunk-02",
|
|
17
|
+
"file": "part02",
|
|
18
|
+
"bytes": 27911957
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
package/extract.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Shared helpers for npm platform packages.
|
|
4
|
+
// The helpers join the data chunks, verify the archive, and extract it.
|
|
5
|
+
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const os = require('node:os');
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const crypto = require('node:crypto');
|
|
10
|
+
const { spawnSync } = require('node:child_process');
|
|
11
|
+
const { createRequire } = require('node:module');
|
|
12
|
+
|
|
13
|
+
const requireFromHere = createRequire(__filename);
|
|
14
|
+
const BUFFER_SIZE = 1024 * 1024;
|
|
15
|
+
|
|
16
|
+
function fail(message) {
|
|
17
|
+
const error = new Error(message);
|
|
18
|
+
error.rustPortable = true;
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function partPath(part) {
|
|
23
|
+
const packageJson = requireFromHere.resolve(`${part.package}/package.json`);
|
|
24
|
+
return path.join(path.dirname(packageJson), part.file);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function joinArchive(archive, destination) {
|
|
28
|
+
const hash = crypto.createHash('sha256');
|
|
29
|
+
const buffer = Buffer.allocUnsafe(BUFFER_SIZE);
|
|
30
|
+
const out = fs.openSync(destination, 'w');
|
|
31
|
+
let written = 0;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
for (const part of archive.parts) {
|
|
35
|
+
const source = partPath(part);
|
|
36
|
+
const stat = fs.statSync(source);
|
|
37
|
+
if (stat.size !== part.bytes) {
|
|
38
|
+
fail(`Chunk size mismatch for ${source}: expected ${part.bytes}, got ${stat.size}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const input = fs.openSync(source, 'r');
|
|
42
|
+
let remaining = part.bytes;
|
|
43
|
+
try {
|
|
44
|
+
while (remaining > 0) {
|
|
45
|
+
const want = Math.min(buffer.length, remaining);
|
|
46
|
+
const read = fs.readSync(input, buffer, 0, want, null);
|
|
47
|
+
if (read <= 0) {
|
|
48
|
+
fail(`Unexpected end of ${source}`);
|
|
49
|
+
}
|
|
50
|
+
hash.update(buffer.subarray(0, read));
|
|
51
|
+
fs.writeSync(out, buffer, 0, read);
|
|
52
|
+
written += read;
|
|
53
|
+
remaining -= read;
|
|
54
|
+
}
|
|
55
|
+
} finally {
|
|
56
|
+
fs.closeSync(input);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} finally {
|
|
60
|
+
fs.closeSync(out);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const actual = hash.digest('hex');
|
|
64
|
+
if (written !== archive.size) {
|
|
65
|
+
fail(`Archive size mismatch: expected ${archive.size}, got ${written}`);
|
|
66
|
+
}
|
|
67
|
+
if (actual !== archive.sha256.toLowerCase()) {
|
|
68
|
+
fail(`Archive SHA256 mismatch: expected ${archive.sha256}, got ${actual}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function tarCommand() {
|
|
73
|
+
if (process.platform !== 'win32') {
|
|
74
|
+
return 'tar';
|
|
75
|
+
}
|
|
76
|
+
const candidate = path.join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'tar.exe');
|
|
77
|
+
if (!fs.existsSync(candidate)) {
|
|
78
|
+
fail(`Windows tar.exe was not found at ${candidate}. Windows 10 1803 or newer is required.`);
|
|
79
|
+
}
|
|
80
|
+
return candidate;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function extractArchive(archivePath, type, destination) {
|
|
84
|
+
fs.mkdirSync(destination, { recursive: true });
|
|
85
|
+
const args = type === 'zip'
|
|
86
|
+
? ['-xf', archivePath, '-C', destination, '--strip-components=1']
|
|
87
|
+
: ['-xzf', archivePath, '-C', destination, '--strip-components=1'];
|
|
88
|
+
const result = spawnSync(tarCommand(), args, { stdio: 'inherit' });
|
|
89
|
+
if (result.error) {
|
|
90
|
+
fail(`Cannot run tar: ${result.error.message}`);
|
|
91
|
+
}
|
|
92
|
+
if (result.status !== 0) {
|
|
93
|
+
fail(`tar failed with exit code ${result.status}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function verifyBundle(directory, platform) {
|
|
98
|
+
if (platform === 'win32-x64') {
|
|
99
|
+
for (const relative of ['windows/configure-env.bat', 'windows/doctor.bat']) {
|
|
100
|
+
if (!fs.existsSync(path.join(directory, relative))) {
|
|
101
|
+
fail(`The archive is missing ${relative}.`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (platform === 'linux-x64' || platform === 'linux-arm64') {
|
|
107
|
+
if (!fs.existsSync(path.join(directory, 'linux', 'install.sh'))) {
|
|
108
|
+
fail('The archive is missing linux/install.sh.');
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
fail(`Unsupported platform: ${platform}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function archiveExtension(type) {
|
|
116
|
+
return type === 'zip' ? 'zip' : 'tar.gz';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function extractBundle(archive, destination) {
|
|
120
|
+
const parent = path.dirname(destination);
|
|
121
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
122
|
+
const suffix = `${process.pid}-${Date.now()}`;
|
|
123
|
+
const temporaryArchive = path.join(
|
|
124
|
+
os.tmpdir(),
|
|
125
|
+
`rust-portable-${archive.platform}-${suffix}.${archiveExtension(archive.type)}`
|
|
126
|
+
);
|
|
127
|
+
const staging = path.join(parent, `.staging-${archive.platform}-${suffix}`);
|
|
128
|
+
|
|
129
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
130
|
+
fs.mkdirSync(staging, { recursive: true });
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
joinArchive(archive, temporaryArchive);
|
|
134
|
+
extractArchive(temporaryArchive, archive.type, staging);
|
|
135
|
+
verifyBundle(staging, archive.platform);
|
|
136
|
+
return staging;
|
|
137
|
+
} catch (error) {
|
|
138
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
139
|
+
throw error;
|
|
140
|
+
} finally {
|
|
141
|
+
fs.rmSync(temporaryArchive, { force: true });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function readText(file) {
|
|
146
|
+
try {
|
|
147
|
+
return fs.readFileSync(file, 'utf8');
|
|
148
|
+
} catch {
|
|
149
|
+
return '';
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function readRelease(directory) {
|
|
154
|
+
const version = readText(path.join(directory, 'VERSION')).trim();
|
|
155
|
+
const buildInfo = readText(path.join(directory, 'BUILD-INFO.txt'));
|
|
156
|
+
const match = /^Bundle revision:[ \t]*(\S+)[ \t]*$/m.exec(buildInfo);
|
|
157
|
+
const revision = match && match[1] !== 'none' ? match[1] : '';
|
|
158
|
+
return { version, revision };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function installedInfo(directory, platform) {
|
|
162
|
+
if (platform === 'win32-x64') {
|
|
163
|
+
return readRelease(directory);
|
|
164
|
+
}
|
|
165
|
+
const root = path.join(directory, 'share', 'rust-portable');
|
|
166
|
+
return readRelease(root);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function bundleInfo(directory) {
|
|
170
|
+
return readRelease(directory);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function isComplete(directory, platform) {
|
|
174
|
+
if (platform === 'win32-x64') {
|
|
175
|
+
return fs.existsSync(path.join(directory, 'windows', 'cargo', 'bin', 'cargo.exe'))
|
|
176
|
+
&& fs.existsSync(path.join(directory, 'windows', 'configure-env.bat'));
|
|
177
|
+
}
|
|
178
|
+
return fs.existsSync(path.join(directory, 'bin', 'rustc'))
|
|
179
|
+
&& fs.existsSync(path.join(directory, 'share', 'rust-portable', 'VERSION'));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function isBundle(directory, platform) {
|
|
183
|
+
if (platform === 'win32-x64') {
|
|
184
|
+
return isComplete(directory, platform);
|
|
185
|
+
}
|
|
186
|
+
return fs.existsSync(path.join(directory, 'linux', 'install.sh'))
|
|
187
|
+
&& fs.existsSync(path.join(directory, 'VERSION'));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function looksLikeInstall(directory, platform) {
|
|
191
|
+
return isComplete(directory, platform) || Boolean(installedInfo(directory, platform).version);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function looksLikeBundle(directory, platform) {
|
|
195
|
+
return isBundle(directory, platform) || Boolean(bundleInfo(directory).version);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function isEmptyDirectory(directory) {
|
|
199
|
+
try {
|
|
200
|
+
return fs.readdirSync(directory).length === 0;
|
|
201
|
+
} catch {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function sameRelease(info, archive) {
|
|
207
|
+
return info.version === archive.bundleVersion
|
|
208
|
+
&& (info.revision || '') === (archive.bundleRevision || '');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
module.exports = {
|
|
212
|
+
fail,
|
|
213
|
+
extractBundle,
|
|
214
|
+
bundleInfo,
|
|
215
|
+
installedInfo,
|
|
216
|
+
isBundle,
|
|
217
|
+
isComplete,
|
|
218
|
+
isEmptyDirectory,
|
|
219
|
+
looksLikeBundle,
|
|
220
|
+
looksLikeInstall,
|
|
221
|
+
sameRelease
|
|
222
|
+
};
|
package/install.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Platform package postinstall.
|
|
5
|
+
//
|
|
6
|
+
// Joins the npm data chunks, verifies the archive, and extracts the portable
|
|
7
|
+
// Rust toolchain into `rust-portable` in the directory where npm was run.
|
|
8
|
+
// The setup command in the entry package controls installation under npx.
|
|
9
|
+
|
|
10
|
+
const fs = require('node:fs');
|
|
11
|
+
const path = require('node:path');
|
|
12
|
+
|
|
13
|
+
const archive = require('./archive.json');
|
|
14
|
+
const pkg = require('./package.json');
|
|
15
|
+
const {
|
|
16
|
+
extractBundle,
|
|
17
|
+
bundleInfo,
|
|
18
|
+
isBundle,
|
|
19
|
+
isEmptyDirectory,
|
|
20
|
+
looksLikeBundle,
|
|
21
|
+
sameRelease
|
|
22
|
+
} = require('./extract');
|
|
23
|
+
|
|
24
|
+
function log(message) {
|
|
25
|
+
console.log(`[rust-portable] ${message}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function fail(message) {
|
|
29
|
+
console.error(`[rust-portable] ${message}`);
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
throw new Error(message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function invocationDirectory() {
|
|
35
|
+
if (process.env.INIT_CWD) return path.resolve(process.env.INIT_CWD);
|
|
36
|
+
if (process.env.npm_config_local_prefix) return path.resolve(process.env.npm_config_local_prefix);
|
|
37
|
+
|
|
38
|
+
const cwd = process.cwd();
|
|
39
|
+
const marker = `${path.sep}node_modules${path.sep}`;
|
|
40
|
+
const index = cwd.indexOf(marker);
|
|
41
|
+
return index === -1 ? cwd : cwd.slice(0, index);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function defaultDestination() {
|
|
45
|
+
if (process.env.RUST_PORTABLE_INSTALL_DIR) {
|
|
46
|
+
return path.resolve(process.env.RUST_PORTABLE_INSTALL_DIR);
|
|
47
|
+
}
|
|
48
|
+
return path.join(invocationDirectory(), 'rust-portable');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function printNextSteps(destination) {
|
|
52
|
+
console.log('');
|
|
53
|
+
log('Next steps:');
|
|
54
|
+
if (archive.platform === 'win32-x64') {
|
|
55
|
+
log(` 1. Run "${path.join(destination, 'windows', 'configure-env.bat')}"`);
|
|
56
|
+
log(' 2. Open a new terminal');
|
|
57
|
+
log(` 3. Run "${path.join(destination, 'windows', 'doctor.bat')}"`);
|
|
58
|
+
} else {
|
|
59
|
+
log(` 1. Run "bash ${path.join(destination, 'linux', 'install.sh')}"`);
|
|
60
|
+
log(' 2. Open a new terminal, or source env.sh');
|
|
61
|
+
log(' 3. Run "<prefix>/share/rust-portable/doctor.sh"');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function main() {
|
|
66
|
+
if (process.env.npm_command === 'exec') {
|
|
67
|
+
// npx: the entry package CLI runs setup.js. Do not extract twice.
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const current = `${process.platform}-${process.arch}`;
|
|
72
|
+
if (current !== archive.platform) {
|
|
73
|
+
fail(`This package is for ${archive.platform}, not ${current}.`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const destination = defaultDestination();
|
|
77
|
+
if (archive.platform === 'win32-x64' && /\s/.test(destination)) {
|
|
78
|
+
fail(
|
|
79
|
+
`Install path contains spaces: ${destination}\n` +
|
|
80
|
+
'Set RUST_PORTABLE_INSTALL_DIR to a path without spaces, for example C:\\rust-portable.'
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const force = process.env.RUST_PORTABLE_FORCE === '1';
|
|
85
|
+
|
|
86
|
+
if (fs.existsSync(destination)) {
|
|
87
|
+
if (!fs.statSync(destination).isDirectory()) {
|
|
88
|
+
fail(`Destination exists and is not a directory: ${destination}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const info = bundleInfo(destination);
|
|
92
|
+
if (isBundle(destination, archive.platform) && sameRelease(info, archive) && !force) {
|
|
93
|
+
log(`${pkg.version} is already installed at ${destination}`);
|
|
94
|
+
printNextSteps(destination);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!looksLikeBundle(destination, archive.platform)
|
|
99
|
+
&& !isEmptyDirectory(destination)
|
|
100
|
+
&& !force) {
|
|
101
|
+
fail(
|
|
102
|
+
`Destination is not a rust-portable install: ${destination}\n` +
|
|
103
|
+
'Choose another RUST_PORTABLE_INSTALL_DIR, or set RUST_PORTABLE_FORCE=1.'
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (looksLikeBundle(destination, archive.platform) && !sameRelease(info, archive) && !force) {
|
|
108
|
+
const installed = info.version || 'an unknown version';
|
|
109
|
+
fail(
|
|
110
|
+
`Destination contains rust-portable ${installed}: ${destination}\n` +
|
|
111
|
+
'Set RUST_PORTABLE_FORCE=1 to replace it.'
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const staging = extractBundle(archive, destination);
|
|
117
|
+
if (fs.existsSync(destination)) {
|
|
118
|
+
fs.rmSync(destination, { recursive: true, force: true });
|
|
119
|
+
}
|
|
120
|
+
fs.renameSync(staging, destination);
|
|
121
|
+
fs.writeFileSync(path.join(destination, '.installed'), `${pkg.version}\n${archive.sha256}\n`);
|
|
122
|
+
log(`Installed to ${destination}`);
|
|
123
|
+
if (archive.platform !== 'win32-x64') {
|
|
124
|
+
log('The bundle is extracted. Run linux/install.sh to install it to a prefix.');
|
|
125
|
+
}
|
|
126
|
+
printNextSteps(destination);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
main();
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (!process.exitCode) {
|
|
133
|
+
console.error(error.stack || String(error));
|
|
134
|
+
process.exitCode = 1;
|
|
135
|
+
}
|
|
136
|
+
process.exit(process.exitCode);
|
|
137
|
+
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ihason/rust-portable-linux-arm64",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.100.0",
|
|
4
|
+
"description": "Portable Rust 1.100.0 toolchain for Linux arm64",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rust",
|
|
7
|
+
"toolchain",
|
|
8
|
+
"portable",
|
|
9
|
+
"windows",
|
|
10
|
+
"linux"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/HasonHuang/rust-portable#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/HasonHuang/rust-portable/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/HasonHuang/rust-portable.git"
|
|
19
|
+
},
|
|
20
|
+
"author": "Hason Huang",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"os": [
|
|
23
|
+
"linux"
|
|
24
|
+
],
|
|
25
|
+
"cpu": [
|
|
26
|
+
"arm64"
|
|
27
|
+
],
|
|
28
|
+
"files": [
|
|
29
|
+
"archive.json",
|
|
30
|
+
"extract.js",
|
|
31
|
+
"setup.js",
|
|
32
|
+
"install.js",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"postinstall": "node install.js"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@ihason/rust-portable-linux-arm64-chunk-01": "1.100.0",
|
|
40
|
+
"@ihason/rust-portable-linux-arm64-chunk-02": "1.100.0"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
}
|
|
4
48
|
}
|
package/setup.js
ADDED
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Interactive and non-interactive setup for one npm platform package.
|
|
5
|
+
// All data comes from the npm chunk packages. The setup does not use GitHub.
|
|
6
|
+
|
|
7
|
+
const fs = require('node:fs');
|
|
8
|
+
const os = require('node:os');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const { spawnSync } = require('node:child_process');
|
|
11
|
+
const readline = require('node:readline/promises');
|
|
12
|
+
|
|
13
|
+
const archive = require('./archive.json');
|
|
14
|
+
const pkg = require('./package.json');
|
|
15
|
+
const {
|
|
16
|
+
extractBundle,
|
|
17
|
+
installedInfo,
|
|
18
|
+
isComplete,
|
|
19
|
+
isEmptyDirectory,
|
|
20
|
+
looksLikeInstall,
|
|
21
|
+
sameRelease
|
|
22
|
+
} = require('./extract');
|
|
23
|
+
|
|
24
|
+
const options = {
|
|
25
|
+
prefix: '',
|
|
26
|
+
system: false,
|
|
27
|
+
user: false,
|
|
28
|
+
configurePath: true,
|
|
29
|
+
installDeps: false,
|
|
30
|
+
force: false,
|
|
31
|
+
runDoctor: true,
|
|
32
|
+
interactive: 'auto',
|
|
33
|
+
help: false
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const originalArgs = process.argv.slice(2);
|
|
37
|
+
let rl = null;
|
|
38
|
+
|
|
39
|
+
function log(message) {
|
|
40
|
+
console.log(`[rust-portable] ${message}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function warn(message) {
|
|
44
|
+
console.error(`[rust-portable] WARNING: ${message}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function fail(message) {
|
|
48
|
+
const error = new Error(message);
|
|
49
|
+
error.rustPortable = true;
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function usage() {
|
|
54
|
+
const platform = archive.platform === 'win32-x64' ? 'Windows' : 'Linux';
|
|
55
|
+
console.log(`Usage: rust-portable setup [options]
|
|
56
|
+
|
|
57
|
+
Install the portable Rust toolchain for ${platform}.
|
|
58
|
+
All data is included in the npm packages. Setup does not use GitHub.
|
|
59
|
+
|
|
60
|
+
Options:
|
|
61
|
+
--prefix DIR Install to DIR. On Windows, DIR is the bundle directory.
|
|
62
|
+
--dir DIR Alias for --prefix on Windows.
|
|
63
|
+
--system Linux: install for all users. Requires sudo.
|
|
64
|
+
--user Linux: install for the current user. Default for non-root.
|
|
65
|
+
--no-path Do not configure PATH.
|
|
66
|
+
--install-deps Linux: install missing system tools.
|
|
67
|
+
--force Replace an existing installation.
|
|
68
|
+
--skip-doctor Do not run the self-check.
|
|
69
|
+
--interactive Ask for the options. A terminal is required.
|
|
70
|
+
--non-interactive Do not ask. Use the options and recommended defaults.
|
|
71
|
+
--yes Same as --non-interactive.
|
|
72
|
+
-h, --help Show this help.
|
|
73
|
+
|
|
74
|
+
When setup has no options and stdin is a terminal, it asks for the options.
|
|
75
|
+
Press Enter to accept the recommended value.`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function parseArgs() {
|
|
79
|
+
let index = 0;
|
|
80
|
+
while (index < originalArgs.length) {
|
|
81
|
+
const arg = originalArgs[index];
|
|
82
|
+
switch (arg) {
|
|
83
|
+
case '--prefix':
|
|
84
|
+
case '--dir':
|
|
85
|
+
if (index + 1 >= originalArgs.length) fail(`${arg} needs a directory`);
|
|
86
|
+
options.prefix = originalArgs[index + 1];
|
|
87
|
+
index += 2;
|
|
88
|
+
break;
|
|
89
|
+
case '--system':
|
|
90
|
+
options.system = true;
|
|
91
|
+
index += 1;
|
|
92
|
+
break;
|
|
93
|
+
case '--user':
|
|
94
|
+
options.user = true;
|
|
95
|
+
index += 1;
|
|
96
|
+
break;
|
|
97
|
+
case '--no-path':
|
|
98
|
+
options.configurePath = false;
|
|
99
|
+
index += 1;
|
|
100
|
+
break;
|
|
101
|
+
case '--install-deps':
|
|
102
|
+
options.installDeps = true;
|
|
103
|
+
index += 1;
|
|
104
|
+
break;
|
|
105
|
+
case '--force':
|
|
106
|
+
options.force = true;
|
|
107
|
+
index += 1;
|
|
108
|
+
break;
|
|
109
|
+
case '--skip-doctor':
|
|
110
|
+
options.runDoctor = false;
|
|
111
|
+
index += 1;
|
|
112
|
+
break;
|
|
113
|
+
case '--interactive':
|
|
114
|
+
options.interactive = 'yes';
|
|
115
|
+
index += 1;
|
|
116
|
+
break;
|
|
117
|
+
case '--non-interactive':
|
|
118
|
+
case '--yes':
|
|
119
|
+
options.interactive = 'no';
|
|
120
|
+
index += 1;
|
|
121
|
+
break;
|
|
122
|
+
case '-h':
|
|
123
|
+
case '--help':
|
|
124
|
+
options.help = true;
|
|
125
|
+
index += 1;
|
|
126
|
+
break;
|
|
127
|
+
default:
|
|
128
|
+
if (arg.startsWith('--prefix=')) {
|
|
129
|
+
options.prefix = arg.slice('--prefix='.length);
|
|
130
|
+
index += 1;
|
|
131
|
+
} else if (arg.startsWith('--dir=')) {
|
|
132
|
+
options.prefix = arg.slice('--dir='.length);
|
|
133
|
+
index += 1;
|
|
134
|
+
} else {
|
|
135
|
+
fail(`unknown option: ${arg}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (options.system && options.user) {
|
|
141
|
+
fail('use --system or --user, not both');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function terminalAvailable() {
|
|
146
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function interactiveEnabled() {
|
|
150
|
+
if (options.interactive === 'no') return false;
|
|
151
|
+
if (options.interactive === 'yes') {
|
|
152
|
+
if (!terminalAvailable()) fail('--interactive needs a terminal');
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
return originalArgs.length === 0 && terminalAvailable();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function openPrompts() {
|
|
159
|
+
rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function closePrompts() {
|
|
163
|
+
if (rl) {
|
|
164
|
+
rl.close();
|
|
165
|
+
rl = null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function ask(prompt, defaultValue) {
|
|
170
|
+
const answer = (await rl.question(`${prompt} [${defaultValue}]: `)).trim();
|
|
171
|
+
return answer || defaultValue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function askYesNo(prompt, defaultValue) {
|
|
175
|
+
const hint = defaultValue ? 'Y/n' : 'y/N';
|
|
176
|
+
const answer = (await rl.question(`${prompt} [${hint}]: `)).trim().toLowerCase();
|
|
177
|
+
if (!answer) return defaultValue;
|
|
178
|
+
return answer === 'y' || answer === 'yes';
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function expandHome(value) {
|
|
182
|
+
if (value === '~') return os.homedir();
|
|
183
|
+
if (value.startsWith('~/')) return path.join(os.homedir(), value.slice(2));
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function normalizePath(value) {
|
|
188
|
+
let result = path.resolve(expandHome(value));
|
|
189
|
+
while (result.length > 1 && result.endsWith(path.sep)) {
|
|
190
|
+
result = result.slice(0, -1);
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function invocationDirectory() {
|
|
196
|
+
if (process.env.INIT_CWD) return path.resolve(process.env.INIT_CWD);
|
|
197
|
+
if (process.env.npm_config_local_prefix) return path.resolve(process.env.npm_config_local_prefix);
|
|
198
|
+
|
|
199
|
+
const cwd = process.cwd();
|
|
200
|
+
const marker = `${path.sep}node_modules${path.sep}`;
|
|
201
|
+
const index = cwd.indexOf(marker);
|
|
202
|
+
return index === -1 ? cwd : cwd.slice(0, index);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function hasCommand(name) {
|
|
206
|
+
const result = spawnSync('sh', ['-c', 'command -v "$1" >/dev/null 2>&1', 'sh', name], {
|
|
207
|
+
stdio: 'ignore'
|
|
208
|
+
});
|
|
209
|
+
return !result.error && result.status === 0;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function missingTools() {
|
|
213
|
+
return ['gcc', 'g++', 'make', 'tar', 'xz', 'find'].filter((tool) => !hasCommand(tool));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function isRoot() {
|
|
217
|
+
return typeof process.getuid === 'function' && process.getuid() === 0;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function decideExisting(directory) {
|
|
221
|
+
if (!fs.existsSync(directory)) {
|
|
222
|
+
return { install: true, force: options.force };
|
|
223
|
+
}
|
|
224
|
+
if (!fs.statSync(directory).isDirectory()) {
|
|
225
|
+
fail(`The destination exists and is not a directory: ${directory}`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const info = installedInfo(directory, archive.platform);
|
|
229
|
+
const complete = isComplete(directory, archive.platform);
|
|
230
|
+
const same = complete && sameRelease(info, archive);
|
|
231
|
+
|
|
232
|
+
if (same && !options.force) {
|
|
233
|
+
if (rl) {
|
|
234
|
+
const again = await askYesNo(
|
|
235
|
+
`rust-portable ${archive.bundleVersion} is already installed at ${directory}. Reinstall`,
|
|
236
|
+
false
|
|
237
|
+
);
|
|
238
|
+
if (!again) return { install: false, force: false };
|
|
239
|
+
return { install: true, force: true };
|
|
240
|
+
}
|
|
241
|
+
return { install: false, force: false };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (!looksLikeInstall(directory, archive.platform)
|
|
245
|
+
&& !isEmptyDirectory(directory)
|
|
246
|
+
&& !options.force) {
|
|
247
|
+
if (rl) {
|
|
248
|
+
const proceed = await askYesNo(
|
|
249
|
+
`The destination is not empty and is not a rust-portable install: ${directory}. Replace its contents`,
|
|
250
|
+
false
|
|
251
|
+
);
|
|
252
|
+
if (!proceed) {
|
|
253
|
+
log('Cancelled.');
|
|
254
|
+
process.exit(0);
|
|
255
|
+
}
|
|
256
|
+
return { install: true, force: true };
|
|
257
|
+
}
|
|
258
|
+
fail(
|
|
259
|
+
`The destination is not empty and is not a rust-portable install: ${directory}\n` +
|
|
260
|
+
'Use --force or another --prefix.'
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (looksLikeInstall(directory, archive.platform) && !same && !options.force) {
|
|
265
|
+
const installed = info.version || 'an unknown version';
|
|
266
|
+
if (rl) {
|
|
267
|
+
const replace = await askYesNo(
|
|
268
|
+
`The destination contains rust-portable ${installed}. Replace it with ${archive.bundleVersion}`,
|
|
269
|
+
false
|
|
270
|
+
);
|
|
271
|
+
if (!replace) {
|
|
272
|
+
log('Cancelled.');
|
|
273
|
+
process.exit(0);
|
|
274
|
+
}
|
|
275
|
+
return { install: true, force: true };
|
|
276
|
+
}
|
|
277
|
+
fail(
|
|
278
|
+
`The destination contains rust-portable ${installed}.\n` +
|
|
279
|
+
'Use --force to replace it.'
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return { install: true, force: options.force };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async function confirm(summary) {
|
|
287
|
+
if (!rl) return true;
|
|
288
|
+
console.log('');
|
|
289
|
+
console.log(summary);
|
|
290
|
+
console.log('');
|
|
291
|
+
const proceed = await askYesNo('Proceed', true);
|
|
292
|
+
if (!proceed) {
|
|
293
|
+
log('Cancelled.');
|
|
294
|
+
process.exit(0);
|
|
295
|
+
}
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function summaryWindows(destination, install) {
|
|
300
|
+
const lines = [
|
|
301
|
+
`rust-portable ${archive.bundleVersion}`,
|
|
302
|
+
' Platform: win32-x64',
|
|
303
|
+
` Directory: ${destination}`,
|
|
304
|
+
` Configure: ${options.configurePath ? 'yes' : 'no'}`,
|
|
305
|
+
` Self-check: ${options.runDoctor ? 'yes' : 'no'}`
|
|
306
|
+
];
|
|
307
|
+
if (!install) {
|
|
308
|
+
lines.push(' Action: already installed');
|
|
309
|
+
}
|
|
310
|
+
return lines.join('\n');
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function summaryLinux(prefix, userLevel, install) {
|
|
314
|
+
const lines = [
|
|
315
|
+
`rust-portable ${archive.bundleVersion}`,
|
|
316
|
+
` Platform: ${archive.platform}`,
|
|
317
|
+
` Prefix: ${prefix}`,
|
|
318
|
+
` Type: ${userLevel ? 'user-level' : 'system-level'}`,
|
|
319
|
+
` Dependencies: ${options.installDeps ? 'install missing tools' : 'do not install'}`,
|
|
320
|
+
` Configure: ${options.configurePath ? 'yes' : 'no'}`,
|
|
321
|
+
` Self-check: ${options.runDoctor ? 'yes' : 'no'}`
|
|
322
|
+
];
|
|
323
|
+
if (!install) {
|
|
324
|
+
lines.push(' Action: already installed, no changes');
|
|
325
|
+
}
|
|
326
|
+
return lines.join('\n');
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function printWindowsNextSteps(destination) {
|
|
330
|
+
console.log('');
|
|
331
|
+
log('Next steps:');
|
|
332
|
+
log(` 1. Run "${path.join(destination, 'windows', 'configure-env.bat')}"`);
|
|
333
|
+
log(' 2. Open a new terminal');
|
|
334
|
+
log(` 3. Run "${path.join(destination, 'windows', 'doctor.bat')}"`);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function printLinuxNextSteps(prefix) {
|
|
338
|
+
console.log('');
|
|
339
|
+
log('Next steps:');
|
|
340
|
+
log(` 1. Activate: . "${path.join(prefix, 'share', 'rust-portable', 'env.sh')}"`);
|
|
341
|
+
log(` 2. Check: "${path.join(prefix, 'share', 'rust-portable', 'doctor.sh')}"`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function runWindowsBatch(destination, name) {
|
|
345
|
+
const file = path.join(destination, 'windows', name);
|
|
346
|
+
if (!fs.existsSync(file)) {
|
|
347
|
+
fail(`Missing file: ${file}`);
|
|
348
|
+
}
|
|
349
|
+
const result = spawnSync(
|
|
350
|
+
process.env.ComSpec || 'cmd.exe',
|
|
351
|
+
['/d', '/c', file, '--no-pause'],
|
|
352
|
+
{ stdio: 'inherit' }
|
|
353
|
+
);
|
|
354
|
+
if (result.error) {
|
|
355
|
+
fail(`Cannot run ${name}: ${result.error.message}`);
|
|
356
|
+
}
|
|
357
|
+
if (result.status !== 0) {
|
|
358
|
+
fail(`${name} failed with exit code ${result.status}`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async function runWindows() {
|
|
363
|
+
if (options.system || options.user) {
|
|
364
|
+
warn('--system and --user are for Linux. They are ignored on Windows.');
|
|
365
|
+
}
|
|
366
|
+
if (options.installDeps) {
|
|
367
|
+
warn('--install-deps is for Linux. It is ignored on Windows.');
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
let destination = options.prefix
|
|
371
|
+
? normalizePath(options.prefix)
|
|
372
|
+
: process.env.RUST_PORTABLE_INSTALL_DIR
|
|
373
|
+
? normalizePath(process.env.RUST_PORTABLE_INSTALL_DIR)
|
|
374
|
+
: path.join(invocationDirectory(), 'rust-portable');
|
|
375
|
+
|
|
376
|
+
if (rl) {
|
|
377
|
+
destination = normalizePath(await ask('Install directory', destination));
|
|
378
|
+
options.configurePath = await askYesNo('Configure Windows user PATH after extraction', true);
|
|
379
|
+
options.runDoctor = await askYesNo('Run the self-check after extraction', true);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (/\s/.test(destination)) {
|
|
383
|
+
fail(
|
|
384
|
+
`The install directory contains spaces: ${destination}\n` +
|
|
385
|
+
'Use --dir with a path without spaces, for example D:\\rust-portable.'
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const decision = await decideExisting(destination);
|
|
390
|
+
if (decision.install || options.configurePath || options.runDoctor) {
|
|
391
|
+
await confirm(summaryWindows(destination, decision.install));
|
|
392
|
+
}
|
|
393
|
+
closePrompts();
|
|
394
|
+
|
|
395
|
+
if (decision.install) {
|
|
396
|
+
const staging = extractBundle(archive, destination);
|
|
397
|
+
if (fs.existsSync(destination)) {
|
|
398
|
+
fs.rmSync(destination, { recursive: true, force: true });
|
|
399
|
+
}
|
|
400
|
+
fs.renameSync(staging, destination);
|
|
401
|
+
log(`Extracted to ${destination}`);
|
|
402
|
+
} else {
|
|
403
|
+
log(`rust-portable ${archive.bundleVersion} is already installed at ${destination}`);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (options.configurePath) {
|
|
407
|
+
log('Configuring the Windows user environment');
|
|
408
|
+
runWindowsBatch(destination, 'configure-env.bat');
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (options.runDoctor) {
|
|
412
|
+
log('Running the self-check');
|
|
413
|
+
runWindowsBatch(destination, 'doctor.bat');
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
printWindowsNextSteps(destination);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
async function runLinux() {
|
|
420
|
+
const root = isRoot();
|
|
421
|
+
const sudo = hasCommand('sudo');
|
|
422
|
+
let userLevel;
|
|
423
|
+
|
|
424
|
+
if (options.system) {
|
|
425
|
+
userLevel = false;
|
|
426
|
+
} else if (options.user) {
|
|
427
|
+
userLevel = true;
|
|
428
|
+
} else {
|
|
429
|
+
userLevel = !root;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
let prefix = options.prefix
|
|
433
|
+
? normalizePath(options.prefix)
|
|
434
|
+
: userLevel
|
|
435
|
+
? path.join(os.homedir(), '.local', 'rust-portable')
|
|
436
|
+
: '/opt/rust-portable';
|
|
437
|
+
|
|
438
|
+
if (rl) {
|
|
439
|
+
if (!root && !options.system && !options.user) {
|
|
440
|
+
console.log('Install type:');
|
|
441
|
+
console.log(` 1) user-level (${path.join(os.homedir(), '.local', 'rust-portable')}) [recommended]`);
|
|
442
|
+
console.log(' 2) system-level (/opt/rust-portable, needs root)');
|
|
443
|
+
const answer = (await rl.question('Select [1]: ')).trim() || '1';
|
|
444
|
+
if (answer === '2') {
|
|
445
|
+
userLevel = false;
|
|
446
|
+
prefix = '/opt/rust-portable';
|
|
447
|
+
} else if (answer !== '1') {
|
|
448
|
+
fail(`invalid selection: ${answer}`);
|
|
449
|
+
}
|
|
450
|
+
} else {
|
|
451
|
+
console.log(`Install type: ${userLevel ? 'user-level' : 'system-level'}`);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
prefix = normalizePath(await ask('Install prefix', prefix));
|
|
455
|
+
|
|
456
|
+
const missing = missingTools();
|
|
457
|
+
if (missing.length > 0 && !options.installDeps) {
|
|
458
|
+
console.log(`Missing system tools: ${missing.join(' ')}`);
|
|
459
|
+
options.installDeps = await askYesNo('Install missing system tools automatically', true);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
options.configurePath = await askYesNo('Configure PATH for future shells', true);
|
|
463
|
+
options.runDoctor = await askYesNo('Run the self-check after installation', true);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (!path.isAbsolute(prefix)) {
|
|
467
|
+
fail(`The install prefix must be an absolute path: ${prefix}`);
|
|
468
|
+
}
|
|
469
|
+
if (prefix === '/') {
|
|
470
|
+
fail('Refusing to install to /');
|
|
471
|
+
}
|
|
472
|
+
if (/\s/.test(prefix)) {
|
|
473
|
+
fail(`The install prefix must not contain spaces: ${prefix}`);
|
|
474
|
+
}
|
|
475
|
+
if (!userLevel && !root && !sudo) {
|
|
476
|
+
fail('System-level install needs sudo. Install sudo or use the default user-level install.');
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const decision = await decideExisting(prefix);
|
|
480
|
+
if (decision.install) {
|
|
481
|
+
await confirm(summaryLinux(prefix, userLevel, decision.install));
|
|
482
|
+
}
|
|
483
|
+
closePrompts();
|
|
484
|
+
|
|
485
|
+
if (!decision.install) {
|
|
486
|
+
log(`rust-portable ${archive.bundleVersion} is already installed at ${prefix}`);
|
|
487
|
+
printLinuxNextSteps(prefix);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'rust-portable-setup-'));
|
|
492
|
+
try {
|
|
493
|
+
const staging = extractBundle(archive, path.join(temporaryRoot, 'bundle'));
|
|
494
|
+
const installer = path.join(staging, 'linux', 'install.sh');
|
|
495
|
+
// Passing --prefix already disables the interactive prompts in install.sh.
|
|
496
|
+
const args = [installer, '--prefix', prefix];
|
|
497
|
+
|
|
498
|
+
if (!options.configurePath) args.push('--no-path');
|
|
499
|
+
if (options.installDeps) args.push('--install-deps');
|
|
500
|
+
if (decision.force) args.push('--force');
|
|
501
|
+
if (!options.runDoctor) args.push('--skip-doctor');
|
|
502
|
+
|
|
503
|
+
const useSudo = !userLevel && !root;
|
|
504
|
+
const command = useSudo ? 'sudo' : 'bash';
|
|
505
|
+
const commandArgs = useSudo ? ['bash', ...args] : args;
|
|
506
|
+
|
|
507
|
+
const result = spawnSync(command, commandArgs, { stdio: 'inherit' });
|
|
508
|
+
if (result.error) {
|
|
509
|
+
fail(`Cannot run the installer: ${result.error.message}`);
|
|
510
|
+
}
|
|
511
|
+
if (result.status !== 0) {
|
|
512
|
+
fail(`The installer failed with exit code ${result.status}`);
|
|
513
|
+
}
|
|
514
|
+
} finally {
|
|
515
|
+
fs.rmSync(temporaryRoot, { recursive: true, force: true });
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
printLinuxNextSteps(prefix);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
async function main() {
|
|
522
|
+
parseArgs();
|
|
523
|
+
if (options.help) {
|
|
524
|
+
usage();
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const current = `${process.platform}-${process.arch}`;
|
|
529
|
+
if (current !== archive.platform) {
|
|
530
|
+
fail(`This package is for ${archive.platform}, not ${current}.`);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (process.platform === 'linux') {
|
|
534
|
+
const report = process.report && process.report.getReport();
|
|
535
|
+
if (report && report.header && !report.header.glibcVersionRuntime) {
|
|
536
|
+
fail('musl-based Linux is not supported. Use a glibc distribution such as Debian, Ubuntu, RHEL or AlmaLinux.');
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (process.platform === 'linux' && isRoot() && process.env.SUDO_USER) {
|
|
541
|
+
fail('Do not run npx with sudo. Run npx as your user; setup uses sudo when needed.');
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const interactive = interactiveEnabled();
|
|
545
|
+
if (interactive) openPrompts();
|
|
546
|
+
|
|
547
|
+
try {
|
|
548
|
+
if (archive.platform === 'win32-x64') {
|
|
549
|
+
await runWindows();
|
|
550
|
+
} else {
|
|
551
|
+
await runLinux();
|
|
552
|
+
}
|
|
553
|
+
} finally {
|
|
554
|
+
closePrompts();
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
main().catch((error) => {
|
|
559
|
+
closePrompts();
|
|
560
|
+
if (error.rustPortable) {
|
|
561
|
+
console.error(`[rust-portable] ERROR: ${error.message}`);
|
|
562
|
+
} else {
|
|
563
|
+
console.error(error.stack || String(error));
|
|
564
|
+
}
|
|
565
|
+
process.exit(1);
|
|
566
|
+
});
|