Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static make binary compilation #70

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dist
docs
coverage
musl-cross
make
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ coverage
*.key
*.pub

# musl repository
musl-cross

#make directory
make

# Personal configs
.vscode/settings.json

Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ package-lock.json
dist
docs
coverage
musl-cross
make
15 changes: 15 additions & 0 deletions bin/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node

import { makeMusl, makeMake } from '../src'

if (process.argv.length < 3) {
throw new Error('Usage: npm run setup -- <musl|make> [config-file]')
}
if (process.argv[2] === 'musl') {
if (process.argv.length < 4) {
throw new Error('Usage: npm run setup -- musl <config-file>')
}
makeMusl(process.argv[3]).catch(console.error)
} else if (process.argv[2] === 'make') {
makeMake().catch(console.error)
}
3,147 changes: 2,282 additions & 865 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"prepack": "git clean -fX dist && tsc --project tsconfig.dist.json",
"start": "tsnd bin/server.ts",
"cli": "ts-node bin/controller.ts",
"setup": "ts-node bin/setup.ts",
"fix": "eslint --fix .",
"postfix": "prettier -w .",
"pretest": "tsc --noEmit",
Expand All @@ -34,7 +35,9 @@
"@types/bonjour": "^3.5.8",
"@types/dockerode": "^3.2.1",
"@types/node": "^14.14.21",
"@types/nodegit": "^0.26.14",
"@types/ssh2": "^0.5.46",
"@types/tar": "^4.0.4",
"@types/yargs": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
Expand All @@ -61,7 +64,9 @@
"fp-ts": "^2.9.5",
"heap-js": "^2.1.4",
"io-ts": "^2.2.14",
"nodegit": "^0.27.0",
"ssh2": "^0.8.9",
"tar": "^4.4.13",
"yargs": "^16.2.0"
}
}
14 changes: 14 additions & 0 deletions src/Setup/import-make.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import http from 'http'
import tar from 'tar'

const URL = 'http://ftp.gnu.org/gnu/make/make-4.3.tar.gz'

async function getMake() {
http.get(URL, (res) => {
res.pipe(tar.x({ strip: 1, cwd: 'make' }))
})
}

export async function makeMake(): Promise<void> {
await getMake()
}
36 changes: 36 additions & 0 deletions src/Setup/import-musl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Clone } from 'nodegit'
import { promises as fs } from 'fs'
import path from 'path'
import { spawn } from 'child_process'

async function cloneMusl(): Promise<void> {
await Clone.clone(
'https://github.com/richfelker/musl-cross-make',
'./musl-cross',
)
}

export async function makeMusl(config: string): Promise<void> {
// requires gnu make on computer
const filename = path.resolve('musl-cross', 'config.mak')
await fs.rm('./musl-cross', { force: true, recursive: true })
await cloneMusl()
if (config) {
await fs.copyFile(config, filename)
} else {
throw new Error('Need config file')
}
process.chdir('./musl-cross')
const command = spawn('make', ['install', './output'])
command.stdout.on('data', (data: Buffer) => {
process.stdout.write(data.toString())
})
command.stderr.on('data', (data: Buffer) => {
process.stderr.write(data.toString())
})
/* await new Promise((resolve, reject) => {
exec('make', (err, stdout, stderr) =>
err ? reject(err) : resolve(stdout + stderr),
)
}) */
}
2 changes: 2 additions & 0 deletions src/Setup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './import-musl'
export * from './import-make'
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './JobOrderer/HeapJobOrderer'
export * from './JobOrderer/JobOrderer'
export * from './JobOrderer/UnknownJobError'
export * from './Zeroconf'
export * from './Setup'