Skip to content

Commit ad1b030

Browse files
committed
fix(foundationdb): macOS - extract from pkg
1 parent bd3f830 commit ad1b030

File tree

1 file changed

+78
-10
lines changed

1 file changed

+78
-10
lines changed

packages/foundationdb/tangram.ts

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as std from "std" with { local: "../std" };
2-
import zlib from "zlib" with { local: "../zlib" };
2+
import { $ } from "std" with { local: "../std" };
3+
import libarchive from "libarchive" with { local: "../libarchive" };
4+
import xar from "xar" with { local: "../xar" };
35
import xz from "xz" with { local: "../xz" };
6+
import zlib from "zlib" with { local: "../zlib" };
47

58
export const metadata = {
69
homepage: "https://www.foundationdb.org/",
7-
hostPlatforms: ["aarch64-linux", "x86_64-linux"],
810
license: "Apache-2.0",
911
name: "foundationdb",
1012
repository: "https://github.com/apple/foundationdb",
@@ -22,13 +24,20 @@ export type Arg = {
2224

2325
export const build = async (...args: std.Args<Arg>) => {
2426
const { build, host } = await std.packages.applyArgs<Arg>(...args);
25-
std.assert.supportedHost(host, metadata);
26-
const checksums = binaryChecksums[host];
27-
tg.assert(checksums !== undefined, `unable to locate checksums for ${host}`);
28-
const arch = std.triple.arch(host);
27+
const os = std.triple.os(host);
28+
if (os === "linux") {
29+
return downloadLinuxPrebuilt(build, host);
30+
} else if (os === "darwin") {
31+
return downloadMacosPrebuilt(build, host);
32+
} else {
33+
return tg.unreachable(`unrecognized os ${os}`);
34+
}
35+
};
36+
37+
export default build;
38+
39+
export const downloadLinuxPrebuilt = async (build: string, host: string) => {
2940
const { repository, version } = metadata;
30-
const binaries = metadata.provides.binaries;
31-
const base = `${repository}/releases/download/${version}`;
3241
const build_ = std.triple.create(std.triple.normalize(build), {
3342
environment: "gnu",
3443
});
@@ -43,6 +52,11 @@ export const build = async (...args: std.Args<Arg>) => {
4352
d.get("lib").then(tg.Directory.expect),
4453
),
4554
]);
55+
const binaries = metadata.provides.binaries;
56+
const checksums = linuxChecksums[host];
57+
tg.assert(checksums !== undefined, `unable to locate checksums for ${host}`);
58+
const arch = std.triple.arch(host);
59+
const base = `${repository}/releases/download/${version}`;
4660
const binDir = Object.fromEntries(
4761
await Promise.all(
4862
binaries.map(async (binary) => {
@@ -72,9 +86,63 @@ export const build = async (...args: std.Args<Arg>) => {
7286
});
7387
};
7488

75-
export default build;
89+
export const downloadMacosPrebuilt = async (build: string, host: string) => {
90+
const { repository, version } = metadata;
91+
const arch = std.triple.arch(host) === "aarch64" ? "arm64" : "x86_64";
92+
const checksum =
93+
arch === "arm64"
94+
? "sha256:b7c65742ad6a9ae1eddd347031a8946546ad35d594a4c78e1448dd9094282135"
95+
: "sha256:0630fd903646f4c5c777c2341ec3671899e2dcc7eca3b4ad8a53c86eb4e8baa6";
96+
const base = `${repository}/releases/download/${version}`;
97+
const fileName = `FoundationDB-${version}_${arch}.pkg`;
98+
const url = `${base}/${fileName}`;
99+
const packageFile = await std.download({ url, checksum }).then((b) => {
100+
tg.assert(b instanceof tg.Blob);
101+
return tg.file(b);
102+
});
103+
104+
return await $`
105+
WORKDIR=$(mktemp -d)
106+
cd $WORKDIR
107+
xar -xf ${packageFile}
108+
gunzip -dc FoundationDB-clients.pkg/Payload | bsdcpio -i
109+
gunzip -dc FoundationDB-server.pkg/Payload | bsdcpio -i
110+
mkdir $OUTPUT
111+
cd $OUTPUT
112+
mkdir -p bin
113+
mkdir -p etc/foundationdb
114+
mkdir -p include/foundationdb
115+
mkdir -p lib
116+
mkdir -p libexec
117+
mkdir -p share/foundationdb
118+
mkdir -p lib/python2.7/site-packages
119+
cp -p $WORKDIR/usr/local/bin/fdbcli bin/
120+
ln -sf ../libexec/backup_agent bin/dr_agent
121+
ln -sf ../libexec/backup_agent bin/fdbbackup
122+
ln -sf ../libexec/backup_agent bin/fdbdr
123+
ln -sf ../libexec/backup_agent bin/fdbrestore
124+
cp -p $WORKDIR/usr/local/libexec/fdbmonitor libexec/
125+
cp -p $WORKDIR/usr/local/libexec/fdbserver libexec/
126+
ln -sf ../libexec/fdbmonitor bin/fdbmonitor
127+
ln -sf ../libexec/fdbserver bin/fdbserver
128+
cp -p $WORKDIR/usr/local/foundationdb/backup_agent/backup_agent libexec/
129+
cp -p $WORKDIR/usr/local/etc/foundationdb/foundationdb.conf.new etc/foundationdb/
130+
cp -p $WORKDIR/usr/local/include/foundationdb/* include/foundationdb/
131+
cp -p $WORKDIR/usr/local/lib/libfdb_c.dylib lib/
132+
cp -rp $WORKDIR/Library/Python/2.7/site-packages/fdb lib/python2.7/site-packages/
133+
mkdir -p share/foundationdb/launchdaemons
134+
cp -p $WORKDIR/Library/LaunchDaemons/com.foundationdb.fdbmonitor.plist share/foundationdb/launchdaemons/
135+
cp -p $WORKDIR/usr/local/foundationdb/README share/foundationdb/
136+
cp -p $WORKDIR/usr/local/foundationdb/uninstall-FoundationDB.sh share/foundationdb/
137+
mkdir -p share/foundationdb/resources
138+
cp -rp $WORKDIR/Resources/* share/foundationdb/resources/
139+
rm -rf $WORKDIR
140+
`
141+
.env(libarchive({ host }), xar({ host }))
142+
.then(tg.Directory.expect);
143+
};
76144

77-
const binaryChecksums: { [key: string]: { [key: string]: tg.Checksum } } = {
145+
const linuxChecksums: { [key: string]: { [key: string]: tg.Checksum } } = {
78146
["aarch64-linux"]: {
79147
fdbcli:
80148
"sha256:a313bf868b06bc86c658efe81b980a62d59223eb4152d61d787534a4e4090066",

0 commit comments

Comments
 (0)