Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit c1e1916

Browse files
committed
support building on more platforms
This adds support for building on a lot more linux platforms. Supported architectures now include x86_64, i686, powerpc64le and aarch64. In addition to that, this adds the ability to use musl on each of these as well, in addition to glibc.
1 parent d4c488a commit c1e1916

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"build": "tsc"
1212
},
1313
"dependencies": {
14-
"rimraf": "^3.0.2"
14+
"rimraf": "^3.0.2",
15+
"detect-libc": "^1.0.3"
1516
},
1617
"devDependencies": {
1718
"@types/node": "14",

src/target.ts

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
import { GLIBC, MUSL, family as processLibC } from "detect-libc"
18+
1719
// We borrow Rust's target naming scheme as a way of expressing all target
1820
// details in a single string.
1921
// See https://doc.rust-lang.org/rustc/platform-support.html.
@@ -23,18 +25,28 @@ export type TargetId =
2325
'universal-apple-darwin' |
2426
'i686-pc-windows-msvc' |
2527
'x86_64-pc-windows-msvc' |
26-
'x86_64-unknown-linux-gnu';
28+
'i686-unknown-linux-musl' |
29+
'i686-unknown-linux-gnu' |
30+
'x86_64-unknown-linux-musl' |
31+
'x86_64-unknown-linux-gnu' |
32+
'aarch64-unknown-linux-musl' |
33+
'aarch64-unknown-linux-gnu' |
34+
'powerpc64le-unknown-linux-musl' |
35+
'powerpc64le-unknown-linux-gnu';
2736

2837
// Values are expected to match those used in `process.platform`.
2938
type Platform = 'darwin' | 'linux' | 'win32';
3039

3140
// Values are expected to match those used in `process.arch`.
32-
type Arch = 'arm64' | 'ia32' | 'x64' | 'universal';
41+
type Arch = 'arm64' | 'ia32' | 'x64' | 'ppc64' | 'universal';
3342

3443
// Values are expected to match those used by Visual Studio's `vcvarsall.bat`.
3544
// See https://docs.microsoft.com/cpp/build/building-on-the-command-line?view=msvc-160#vcvarsall-syntax
3645
type VcVarsArch = 'amd64' | 'arm64' | 'x86';
3746

47+
// Values are expected to match those used in `detect-libc`.
48+
type LibC = GLIBC | MUSL;
49+
3850
export type Target = {
3951
id: TargetId;
4052
platform: Platform;
@@ -46,6 +58,11 @@ export type WindowsTarget = Target & {
4658
vcVarsArch: VcVarsArch;
4759
}
4860

61+
export type LinuxTarget = Target & {
62+
platform: 'linux';
63+
libC: LibC;
64+
}
65+
4966
export type UniversalTarget = Target & {
5067
arch: 'universal',
5168
subtargets: Target[],
@@ -87,10 +104,60 @@ const x8664PcWindowsMsvc: WindowsTarget = {
87104
vcVarsArch: 'amd64',
88105
}
89106

90-
const x8664UnknownLinuxGnu: Target = {
107+
const x8664UnknownLinuxGnu: LinuxTarget = {
91108
id: 'x86_64-unknown-linux-gnu',
92109
platform: 'linux',
93110
arch: 'x64',
111+
libC: 'glibc',
112+
};
113+
114+
const x8664UnknownLinuxMusl: LinuxTarget = {
115+
id: 'x86_64-unknown-linux-musl',
116+
platform: 'linux',
117+
arch: 'x64',
118+
libC: 'musl',
119+
};
120+
121+
const i686UnknownLinuxGnu: LinuxTarget = {
122+
id: 'i686-unknown-linux-gnu',
123+
platform: 'linux',
124+
arch: 'ia32',
125+
libC: 'glibc',
126+
};
127+
128+
const i686UnknownLinuxMusl: LinuxTarget = {
129+
id: 'i686-unknown-linux-musl',
130+
platform: 'linux',
131+
arch: 'ia32',
132+
libC: 'musl',
133+
};
134+
135+
const aarch64UnknownLinuxGnu: LinuxTarget = {
136+
id: 'aarch64-unknown-linux-gnu',
137+
platform: 'linux',
138+
arch: 'arm64',
139+
libC: 'glibc',
140+
};
141+
142+
const aarch64UnknownLinuxMusl: LinuxTarget = {
143+
id: 'aarch64-unknown-linux-musl',
144+
platform: 'linux',
145+
arch: 'arm64',
146+
libC: 'musl',
147+
};
148+
149+
const powerpc64leUnknownLinuxGnu: LinuxTarget = {
150+
id: 'powerpc64le-unknown-linux-gnu',
151+
platform: 'linux',
152+
arch: 'ppc64',
153+
libC: 'glibc',
154+
};
155+
156+
const powerpc64leUnknownLinuxMusl: LinuxTarget = {
157+
id: 'powerpc64le-unknown-linux-musl',
158+
platform: 'linux',
159+
arch: 'ppc64',
160+
libC: 'musl',
94161
};
95162

96163
export const TARGETS: Record<TargetId, Target> = {
@@ -99,7 +166,14 @@ export const TARGETS: Record<TargetId, Target> = {
99166
'universal-apple-darwin': universalAppleDarwin,
100167
'i686-pc-windows-msvc': i686PcWindowsMsvc,
101168
'x86_64-pc-windows-msvc': x8664PcWindowsMsvc,
169+
'i686-unknown-linux-musl': i686UnknownLinuxMusl,
170+
'i686-unknown-linux-gnu': i686UnknownLinuxGnu,
171+
'x86_64-unknown-linux-musl': x8664UnknownLinuxMusl,
102172
'x86_64-unknown-linux-gnu': x8664UnknownLinuxGnu,
173+
'aarch64-unknown-linux-musl': aarch64UnknownLinuxMusl,
174+
'aarch64-unknown-linux-gnu': aarch64UnknownLinuxGnu,
175+
'powerpc64le-unknown-linux-musl': powerpc64leUnknownLinuxMusl,
176+
'powerpc64le-unknown-linux-gnu': powerpc64leUnknownLinuxGnu,
103177
};
104178

105179
// The set of targets we build by default, sorted by increasing complexity so
@@ -113,7 +187,11 @@ export const ENABLED_TARGETS: Target[] = [
113187
export function getHost(): Target {
114188
return Object.values(TARGETS).find(target => (
115189
target.platform === process.platform &&
116-
target.arch === process.arch
190+
target.arch === process.arch &&
191+
(
192+
process.platform !== 'linux' ||
193+
(target as LinuxTarget).libC === processLibC
194+
)
117195
));
118196
}
119197

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ deep-is@^0.1.3:
338338
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
339339
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
340340

341+
detect-libc@^1.0.3:
342+
version "1.0.3"
343+
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
344+
integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=
345+
341346
diff@^4.0.1:
342347
version "4.0.2"
343348
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"

0 commit comments

Comments
 (0)