Skip to content

Commit

Permalink
feat: add musl build
Browse files Browse the repository at this point in the history
Closes #702
  • Loading branch information
timsuchanek committed May 6, 2020
1 parent 111b4cd commit 7bdf025
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 67 deletions.
3 changes: 1 addition & 2 deletions src/packages/engine-core/src/NodeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const knownPlatforms: Platform[] = [
'debian-openssl-1.1.x',
'rhel-openssl-1.0.x',
'rhel-openssl-1.1.x',
'musl-openssl-1.0.x',
'musl-openssl-1.1.x',
'linux-musl',
'windows',
]

Expand Down
3 changes: 1 addition & 2 deletions src/packages/fetch-engine/scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ download({
'debian-openssl-1.1.x',
'rhel-openssl-1.0.x',
'rhel-openssl-1.1.x',
'musl-openssl-1.0.x',
'musl-openssl-1.1.x',
'linux-musl',
],
showProgress: true,
})
70 changes: 42 additions & 28 deletions src/packages/fetch-engine/src/__tests__/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ describe('download', () => {
'introspection-engine': __dirname,
'migration-engine': __dirname,
},
version: '1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3',
version: 'fc45fde2be3f39a089ade64c5c480b7ac30af461',
})

expect(await getVersion(queryEnginePath)).toMatchInlineSnapshot(
`"prisma 1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3"`,
`"query-engine fc45fde2be3f39a089ade64c5c480b7ac30af461"`,
)
expect(await getVersion(introspectionEnginePath)).toMatchInlineSnapshot(
`"introspection-core 1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3"`,
`"introspection-core fc45fde2be3f39a089ade64c5c480b7ac30af461"`,
)
expect(await getVersion(migrationEnginePath)).toMatchInlineSnapshot(
`"migration-engine-cli 1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3"`,
`"migration-engine-cli fc45fde2be3f39a089ade64c5c480b7ac30af461"`,
)
})

Expand All @@ -73,7 +73,7 @@ describe('download', () => {
binaries: {
'query-engine': baseDir,
},
version: '1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3',
version: 'fc45fde2be3f39a089ade64c5c480b7ac30af461',
})

fs.writeFileSync(targetPath, 'incorrect-binary')
Expand All @@ -83,7 +83,7 @@ describe('download', () => {
binaries: {
'query-engine': baseDir,
},
version: '1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3',
version: 'fc45fde2be3f39a089ade64c5c480b7ac30af461',
})

expect(fs.existsSync(targetPath)).toBe(true)
Expand All @@ -97,7 +97,7 @@ describe('download', () => {
binaries: {
'query-engine': __dirname,
},
version: '1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3',
version: 'fc45fde2be3f39a089ade64c5c480b7ac30af461',
binaryTargets: ['darwin', 'marvin'] as any, // eslint-disable-line @typescript-eslint/no-explicit-any
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -120,8 +120,9 @@ describe('download', () => {
'rhel-openssl-1.0.x',
'rhel-openssl-1.1.x',
'windows',
'linux-musl',
],
version: '1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3',
version: 'fc45fde2be3f39a089ade64c5c480b7ac30af461',
})
const files = getFiles(baseDir)
expect(files).toMatchInlineSnapshot(`
Expand All @@ -132,75 +133,87 @@ describe('download', () => {
},
Object {
"name": "introspection-engine-darwin",
"size": 11217352,
"size": 11073588,
},
Object {
"name": "introspection-engine-debian-openssl-1.0.x",
"size": 14144184,
"size": 14162168,
},
Object {
"name": "introspection-engine-debian-openssl-1.1.x",
"size": 14117656,
"size": 14139536,
},
Object {
"name": "introspection-engine-linux-musl",
"size": 17111544,
},
Object {
"name": "introspection-engine-rhel-openssl-1.0.x",
"size": 14184811,
"size": 14224308,
},
Object {
"name": "introspection-engine-rhel-openssl-1.1.x",
"size": 14164268,
"size": 14202662,
},
Object {
"name": "introspection-engine-windows.exe",
"size": 23438433,
"size": 23227789,
},
Object {
"name": "migration-engine-darwin",
"size": 14817144,
"size": 14499444,
},
Object {
"name": "migration-engine-debian-openssl-1.0.x",
"size": 17972920,
"size": 17714760,
},
Object {
"name": "migration-engine-debian-openssl-1.1.x",
"size": 17946184,
"size": 17683720,
},
Object {
"name": "migration-engine-linux-musl",
"size": 20504024,
},
Object {
"name": "migration-engine-rhel-openssl-1.0.x",
"size": 18030001,
"size": 17788921,
},
Object {
"name": "migration-engine-rhel-openssl-1.1.x",
"size": 18009213,
"size": 17763228,
},
Object {
"name": "migration-engine-windows.exe",
"size": 28021828,
"size": 27496535,
},
Object {
"name": "query-engine-darwin",
"size": 16575264,
"size": 16149612,
},
Object {
"name": "query-engine-debian-openssl-1.0.x",
"size": 19918856,
"size": 19680168,
},
Object {
"name": "query-engine-debian-openssl-1.1.x",
"size": 19897512,
"size": 19652760,
},
Object {
"name": "query-engine-linux-musl",
"size": 22338512,
},
Object {
"name": "query-engine-rhel-openssl-1.0.x",
"size": 19963237,
"size": 19721089,
},
Object {
"name": "query-engine-rhel-openssl-1.1.x",
"size": 19943763,
"size": 19699148,
},
Object {
"name": "query-engine-windows.exe",
"size": 30330977,
"size": 29877206,
},
]
`)
Expand All @@ -219,8 +232,9 @@ describe('download', () => {
'rhel-openssl-1.0.x',
'rhel-openssl-1.1.x',
'windows',
'linux-musl',
],
version: '1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3',
version: 'fc45fde2be3f39a089ade64c5c480b7ac30af461',
})
const after = Date.now()
// cache should take less than 2s
Expand All @@ -241,7 +255,7 @@ describe('download', () => {
'rhel-openssl-1.1.x',
'windows',
],
version: '1743b1e3c8fbe24cb345528ab0cf3013cdc36fa3',
version: 'fc45fde2be3f39a089ade64c5c480b7ac30af461',
})
const after2 = Date.now()
// if binaries are already there, it should take less than 100ms to check all of them
Expand Down
50 changes: 22 additions & 28 deletions src/packages/fetch-engine/src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ export async function download(options: DownloadOptions): Promise<BinaryPaths> {
const platform = await getPlatform()
const os = await getos()

if (os.distro === 'musl') {
console.error(
`${chalk.yellow(
'Warning',
)} Precompiled binaries are not available for Alpine.`,
)
} else if (os.distro === 'arm') {
if (os.distro === 'arm') {
console.error(
`${chalk.yellow(
'Warning',
Expand Down Expand Up @@ -168,29 +162,27 @@ export async function download(options: DownloadOptions): Promise<BinaryPaths> {
}

// Node 14 for whatever reason can't handle concurrent writes
if (process.version.startsWith('v14')) {
for (const job of binariesToDownload) {
await downloadBinary({
// if (process.version.startsWith('v14')) {
// for (const job of binariesToDownload) {
// await downloadBinary({
// ...job,
// version: options.version,
// failSilent: options.failSilent,
// progressCb: setProgress ? setProgress(job.targetFilePath) : undefined,
// })
// }
// } else {
await Promise.all(
binariesToDownload.map((job) =>
downloadBinary({
...job,
version: options.version,
failSilent: options.failSilent,
progressCb: setProgress ? setProgress(job.targetFilePath) : undefined,
})
}
} else {
await Promise.all(
binariesToDownload.map((job) =>
downloadBinary({
...job,
version: options.version,
failSilent: options.failSilent,
progressCb: setProgress
? setProgress(job.targetFilePath)
: undefined,
}),
),
)
}
}),
),
)
// }

await cleanupPromise // make sure, that cleanup finished
if (finishBar) {
Expand Down Expand Up @@ -276,14 +268,16 @@ async function binaryNeedsToBeDownloaded(
const sha256FilePath = cachedFile + '.sha256'
if (await exists(sha256FilePath)) {
const sha256File = await readFile(sha256FilePath, 'utf-8')
const sha256Cache = await hasha.fromFile(cachedFile, {
// TODO: Use `fromFile` as soon as https://github.com/nodejs/node/issues/33263 is fixed
const sha256Cache = await hasha.fromFileSync(cachedFile, {
algorithm: 'sha256',
})
if (sha256File === sha256Cache) {
if (!targetExists) {
await copy(cachedFile, job.targetFilePath)
}
const targetSha256 = await hasha.fromFile(job.targetFilePath, {
// TODO: Use `fromFile` as soon as https://github.com/nodejs/node/issues/33263 is fixed
const targetSha256 = await hasha.fromFileSync(job.targetFilePath, {
algorithm: 'sha256',
})
if (sha256File !== targetSha256) {
Expand Down
6 changes: 2 additions & 4 deletions src/packages/get-platform/src/platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export type Platform =
| 'debian-openssl-1.1.x'
| 'rhel-openssl-1.0.x'
| 'rhel-openssl-1.1.x'
| 'musl-openssl-1.0.x'
| 'musl-openssl-1.1.x'
| 'linux-musl'
| 'windows'
| 'freebsd'
| 'openbsd'
Expand All @@ -18,8 +17,7 @@ export const platforms = [
'debian-openssl-1.1.x',
'rhel-openssl-1.0.x',
'rhel-openssl-1.1.x',
'musl-openssl-1.0.x',
'musl-openssl-1.1.x',
'linux-musl',
'windows',
]

Expand Down
4 changes: 1 addition & 3 deletions src/packages/sdk/src/getGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,14 @@ export const knownBinaryTargets: Platform[] = [
'debian-openssl-1.1.x',
'rhel-openssl-1.0.x',
'rhel-openssl-1.1.x',
'musl-openssl-1.0.x',
'musl-openssl-1.1.x',
'linux-musl',
'windows',
]

const oldToNewBinaryTargetsMapping = {
'linux-glibc-libssl1.0.1': 'debian-openssl-1.0.x',
'linux-glibc-libssl1.0.2': 'debian-openssl-1.0.x',
'linux-glibc-libssl1.1.0': 'debian-openssl1.1.x',
'linux-musl-libssl1.1.0': 'debian-openssl1.1.x',
}

async function validateGenerators(
Expand Down

0 comments on commit 7bdf025

Please sign in to comment.