-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prebuilt-tdlib: change the package structure to use optionalDependencies
(this is untested for now)
- Loading branch information
Showing
15 changed files
with
347 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
prebuilds/tdlib-* | ||
prebuilds/*.json | ||
to-upload/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Blue Oak Model License | ||
|
||
Version 1.0.0 | ||
|
||
## Purpose | ||
|
||
This license gives everyone as much permission to work with | ||
this software as possible, while protecting contributors | ||
from liability. | ||
|
||
## Acceptance | ||
|
||
In order to receive this license, you must agree to its | ||
rules. The rules of this license are both obligations | ||
under that agreement and conditions to your license. | ||
You must not do anything with this software that triggers | ||
a rule that you cannot or will not follow. | ||
|
||
## Copyright | ||
|
||
Each contributor licenses you to do everything with this | ||
software that would otherwise infringe that contributor's | ||
copyright in it. | ||
|
||
## Notices | ||
|
||
You must ensure that everyone who gets a copy of | ||
any part of this software from you, with or without | ||
changes, also gets the text of this license or a link to | ||
<https://blueoakcouncil.org/license/1.0.0>. | ||
|
||
## Excuse | ||
|
||
If anyone notifies you in writing that you have not | ||
complied with [Notices](#notices), you can keep your | ||
license by taking all practical steps to comply within 30 | ||
days after the notice. If you do not do so, your license | ||
ends immediately. | ||
|
||
## Patent | ||
|
||
Each contributor licenses you to do everything with this | ||
software that would otherwise infringe any patent claims | ||
they can license or become able to license. | ||
|
||
## Reliability | ||
|
||
No contributor can revoke this license. | ||
|
||
## No Liability | ||
|
||
***As far as the law allows, this software comes as is, | ||
without any warranty or condition, and no contributor | ||
will be liable to anyone for any damages related to this | ||
software or this license, under any kind of legal claim.*** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
# Prebuilt TDLib | ||
|
||
This package distributes pre-built [TDLib][] shared libraries through npm. | ||
The libraries are built on GitHub Actions: [prebuilt-tdlib.yml][]. | ||
The libraries are built on GitHub Actions ([prebuilt-tdlib.yml][]) and published | ||
using [npm publish --provenance][provenance]. | ||
|
||
[TDLib]: https://github.com/tdlib/td | ||
[prebuilt-tdlib.yml]: ../../.github/workflows/prebuilt-tdlib.yml | ||
[provenance]: https://docs.npmjs.com/generating-provenance-statements | ||
|
||
The shared libraries are statically linked against OpenSSL and zlib to prevent | ||
compatibility issues in Node.js. | ||
The shared libraries are statically linked against OpenSSL and zlib, for one, to | ||
prevent compatibility issues in Node.js. | ||
|
||
Supported systems: | ||
- Linux x86_64 (requires glibc >= 2.22) | ||
|
@@ -32,7 +34,8 @@ $ npm install [email protected] | |
`$ npm info prebuilt-tdlib dist-tags` to get the list of available versions. | ||
|
||
The TDLib version is important: there is no backward compatibility and the | ||
interface you use may significantly change after an update. | ||
interface you use may significantly change after an update. It is, though, | ||
recommended to use the latest TDLib version. | ||
|
||
## Usage | ||
|
||
|
@@ -111,7 +114,6 @@ An incomplete list is available below (mostly exceptions or "notable" versions): | |
| npm tag | notes | | ||
| ------- | ----- | | ||
| [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.26.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.26) | [tdlib [b1b33cf42790ca10ef34abc2ac8828ae704f1f56](https://github.com/tdlib/td/commit/b1b33cf42790ca10ef34abc2ac8828ae704f1f56)] | | ||
| [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.19.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.19) | | | ||
| [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.14.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.14) | [tdlib [66234ae2537a99ec0eaf7b0857245a6e5c2d2bc9](https://github.com/tdlib/td/commit/66234ae2537a99ec0eaf7b0857245a6e5c2d2bc9)] | | ||
| [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.12.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.12) | [tdlib [70bee089d492437ce931aa78446d89af3da182fc](https://github.com/tdlib/td/commit/70bee089d492437ce931aa78446d89af3da182fc)] | | ||
| [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.7.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.7) | [tdlib [de5379f00b6af7686f197037ca3b494e6277e523](https://github.com/tdlib/td/commit/de5379f00b6af7686f197037ca3b494e6277e523)] | | ||
|
@@ -123,10 +125,21 @@ Changes to the building process of `prebuilt-tdlib` are noted below. | |
|
||
### (unreleased) | ||
|
||
The building process of Linux and macOS builds is significantly changed. | ||
|
||
- on macOS, TDLib is built using macOS SDK from nixpkgs, and the minimal | ||
supported macOS version is now 10.12 instead of 10.14. | ||
First published as `<unpublished>`. | ||
|
||
The building process is significantly changed in this update. | ||
|
||
- Changed the structure of the package: instead of packing all binaries into the | ||
prebuilt-tdlib package, every binary is split into a separate package, and all | ||
the packages are specified in `optionalDependencies` of `prebuilt-tdlib`. The | ||
same approach is used by, e.g., esbuild and swc. This installs a binary for | ||
the user's system only, allowing `prebuilt-tdlib` to potentially scale for | ||
more architectures and libc variants. One downside is that `node_modules` | ||
can't simply be copied to a different platform anymore. | ||
- On macOS, TDLib is built using macOS SDK from nixpkgs, and the minimal | ||
supported macOS version is now 10.12 instead of 10.14. The arm64 macOS | ||
library is now tested in the CI using the macos-14 GitHub runner (and not | ||
crosscompiled anymore). | ||
- On Linux, TDLib is now built using zig. The minimal glibc version is 2.22 | ||
instead of 2.17. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/** Currently present for forward compatibility only. */ | ||
export type Options = { | ||
libc: 'glibc' | ||
readonly forceLibc?: 'glibc' | 'musl' | ||
} | ||
|
||
export declare function getTdjson(options?: Options): string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,53 @@ | ||
// @flow | ||
|
||
const path = require('path') | ||
const fs = require('fs') | ||
const { prebuilds } = require('./prebuild-list') | ||
|
||
const SCOPE = '@prebuilt-tdlib' | ||
|
||
// For now, the `Options` object is present for forward compatibility. | ||
// TODO: Add an option like "fallback"? | ||
/*:: | ||
export type Options = { | ||
// Can be 'glibc' | 'musl' in the future | ||
libc: 'glibc' | ||
+forceLibc?: 'glibc' | 'musl' | ||
} | ||
*/ | ||
|
||
function prebuild (pathcomps/*: string[] */) { | ||
return path.resolve(__dirname, 'prebuilds', ...pathcomps) | ||
} | ||
let libcNameCache = null | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
function getTdjson (options/*:: ?: Options */)/*: string */ { | ||
const platform = process.platform + '-' + process.arch | ||
switch (platform) { | ||
case 'win32-x64': return prebuild(['tdlib-windows-x64', 'tdjson.dll']) | ||
case 'darwin-x64': return prebuild(['tdlib-macos', 'libtdjson.dylib']) | ||
case 'darwin-arm64': return prebuild(['tdlib-macos', 'libtdjson.dylib']) | ||
case 'linux-x64': return prebuild(['tdlib-linux-x64', 'libtdjson.so']) | ||
case 'android-x64': return prebuild(['tdlib-linux-x64', 'libtdjson.so']) | ||
default: throw new Error(`The ${platform} platform is not supported`) | ||
function detectLibc ()/*: 'glibc' | 'musl' */ { | ||
// This function can return false results: it currently only checks for | ||
// Alpine Linux as a heuristic (the same approach is used by node-gyp-build). | ||
if (libcNameCache != null) return libcNameCache | ||
let result = 'glibc' | ||
try { | ||
if (fs.existsSync('/etc/alpine-release')) | ||
result = 'musl' | ||
} catch (e) { | ||
// Intentionally empty (defaults to 'glibc') | ||
} | ||
libcNameCache = result | ||
return result | ||
} | ||
|
||
module.exports = { getTdjson } | ||
exports.getTdjson = function getTdjson (options/*:: ?: Options */)/*: string */ { | ||
let { platform, arch } = process | ||
if (platform === 'android') platform = 'linux' | ||
const libc = options?.forceLibc || (platform === 'linux' ? detectLibc() : null) | ||
for (const prebuild of prebuilds) { | ||
if (prebuild.requirements.os != null) | ||
if (!prebuild.requirements.os.includes(platform)) continue | ||
if (prebuild.requirements.cpu != null) | ||
if (!prebuild.requirements.cpu.includes(arch)) continue | ||
if (prebuild.libc != null && prebuild.libc !== libc) continue | ||
// Found a prebuild for the current platform | ||
const pkg = `${SCOPE}/${prebuild.packageName}/${prebuild.libfile}` | ||
try { | ||
return require.resolve(pkg) | ||
} catch (e) { | ||
throw new Error(`Could not load ${pkg} (are optionalDependencies installed?): ${e?.message}`) | ||
} | ||
} | ||
let entirePlatform = `${platform}-${arch}` | ||
if (libc != null) entirePlatform += '-' + libc | ||
throw new Error(`The ${entirePlatform} platform is not supported`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,13 @@ | |
}, | ||
"files": [ | ||
"index.js", | ||
"prebuild-list.js", | ||
"index.d.ts", | ||
"prebuilds" | ||
"LICENSE.md" | ||
], | ||
"optionalDependencies": {}, | ||
"author": "Bannerets <[email protected]>", | ||
"license": "MIT", | ||
"license": "BlueOak-1.0.0", | ||
"keywords": [ | ||
"telegram", | ||
"telegram-api", | ||
|
@@ -28,5 +30,9 @@ | |
"url": "https://github.com/Bannerets/tdl/issues" | ||
}, | ||
"homepage": "https://github.com/Bannerets/tdl/tree/main/packages/prebuilt-tdlib#readme", | ||
"tdlib": { | ||
"commit": "unknown", | ||
"version": "unknown" | ||
}, | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @flow | ||
|
||
/*:: | ||
export type PrebuildInfo = { | ||
packageName: string, | ||
prebuildDir: string, | ||
libfile: string, | ||
descr: string, | ||
requirements: { os?: string[], cpu?: string[] }, | ||
libc?: 'glibc' | 'musl' | ||
} | ||
*/ | ||
|
||
const SHARED_LINUX = 'libtdjson.so' | ||
const SHARED_MACOS = 'libtdjson.dylib' | ||
const SHARED_WINDOWS = 'tdjson.dll' | ||
|
||
const prebuilds/*: PrebuildInfo[] */ = [ | ||
{ | ||
packageName: 'win32-x64', | ||
prebuildDir: 'tdlib-windows-x86_64', | ||
libfile: SHARED_WINDOWS, | ||
descr: 'Windows x86_64', | ||
requirements: { | ||
os: ['win32'], | ||
cpu: ['x64'] | ||
} | ||
}, | ||
{ | ||
packageName: 'darwin', | ||
prebuildDir: 'tdlib-macos', | ||
libfile: SHARED_MACOS, | ||
descr: 'macOS (universal)', | ||
requirements: { | ||
os: ['darwin'] | ||
} | ||
}, | ||
{ | ||
packageName: 'linux-x64-glibc', | ||
prebuildDir: 'tdlib-linux-x86_64-glibc', | ||
libfile: SHARED_LINUX, | ||
descr: 'Linux x86_64 (glibc)', | ||
requirements: { | ||
os: ['linux'], | ||
cpu: ['x64'] | ||
}, | ||
libc: 'glibc' | ||
} | ||
] | ||
|
||
exports.prebuilds = prebuilds |
Oops, something went wrong.