-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-cygwin.js
108 lines (90 loc) · 3.38 KB
/
build-cygwin.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const os = require("os")
const path = require("path")
const mkdirp = require("mkdirp")
const download = require("download")
const cp = require("child_process")
const rimraf = require("rimraf");
const fs = require("fs-extra");
process.env['npm_config_strict_ssl'] = 'false';
const log = (msg) => console.log(msg)
const install = async () => {
// Several of these constants are borrowed from:
// https://github.com/ocaml/ocaml-ci-scripts/blob/master/appveyor-install.ps1
const cygSetup = "setup-x86_64.exe"
const cygDownloadPath = `https://cygwin.com/${cygSetup}`
const cygMirror = "http://cygwin.mirror.constant.com"
const packagesToInstall = [
// Needed for cross-compilation to Windows native executables
"mingw64-x86_64-gcc-core",
"mingw64-x86_64-gcc-g++",
"mingw64-x86_64-headers",
"mingw64-x86_64-runtime",
"mingw64-x86_64-winpthreads",
// Linux utilities - 'bashisms' to support development
"curl",
"diff",
"diffutils",
"git",
"m4",
"make",
"patch",
"unzip",
"python",
"bash"
// Needed for installing the cygwin-build of OCaml
// May not be needed
// "gcc-g++",
// "flexdll",
]
const destinationFolder = path.join(__dirname, ".cygwin")
const localPackageDirectory = path.join(destinationFolder, "var", "cache", "setup")
const cygSetupPath = path.join(destinationFolder, cygSetup)
log(`Creating folder: ${destinationFolder}`)
mkdirp.sync(destinationFolder)
log(`Downloading setup from: ${cygDownloadPath} to: ${destinationFolder}`)
await download(cygDownloadPath, destinationFolder)
log(`Download complete!`)
log(`Installing packages...`)
cp.spawnSync(cygSetupPath, [
"-qWnNdO",
"-R",
destinationFolder,
"-s",
cygMirror,
"-l",
localPackageDirectory,
"-P",
packagesToInstall.join(",")
], {
stdio: [process.stdin, process.stdout, process.stderr],
encoding: "utf-8",
})
log(`Installation complete!`)
// Delete the /var/cache folder, since it's large and we don't need the cache at this point
console.log("Deleting /var/cache...");
rimraf.sync(path.join(__dirname, ".cygwin", "var", "cache"));
console.log("Deletion successful!");
// Copy any overridden configuration scripts to the cygwin folder
console.log("Copying over defaults...");
fs.copySync(path.join(__dirname, "defaults"), path.join(__dirname, ".cygwin"));
console.log("Defaults copied successfully");
// Explicitly set home directory
try {
fs.appendFileSync(
path.join(__dirname, ".cygwin", "etc", "nsswitch.conf"),
"\ndb_home: /usr/esy\n"
);
} catch(e) {
console.error("Something went wrong while updating nsswitch.conf");
}
// Run a command to test it out & create initial script files
cp.spawnSync(path.join(__dirname, "re", "_build", "default", "bin", "EsyBash.exe"), ["bash", "-lc", "cd ~ && pwd"]);
console.log("Verifying esy profile set up...");
const bashRcContents = fs.readFileSync(path.join(__dirname, ".cygwin", "usr", "esy", ".bashrc")).toString("utf8");
console.log("Esy user profile setup!");
}
if (os.platform() === "win32") {
install()
} else {
console.log("Not Windows; Cygwin is not required.")
}