64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
/**
|
|
* Brotli — high-ratio compression. Backs the `br` Content-Encoding in fetch
|
|
* and bun's --compress bundler flag.
|
|
*
|
|
* DirectBuild: one archive containing common + dec + enc. The cmake build
|
|
* splits these into three libs purely so dec-only consumers can avoid the
|
|
* encoder; we link everything anyway, so a single .a is simpler and drops
|
|
* the "common must come last" link-order footgun.
|
|
*/
|
|
|
|
import type { Dependency, DirectBuild } from "../source.ts";
|
|
|
|
// Upstream brotli pins releases by tag, not commit. A retag would change
|
|
// what we fetch — if that ever matters, resolve the tag to a sha and pin that.
|
|
const BROTLI_COMMIT = "v1.1.0";
|
|
|
|
// prettier-ignore
|
|
const SOURCES = [
|
|
"common/constants", "common/context", "common/dictionary", "common/platform",
|
|
"common/shared_dictionary", "common/transform",
|
|
"dec/bit_reader", "dec/decode", "dec/huffman", "dec/state",
|
|
"enc/backward_references", "enc/backward_references_hq", "enc/bit_cost",
|
|
"enc/block_splitter", "enc/brotli_bit_stream", "enc/cluster", "enc/command",
|
|
"enc/compound_dictionary", "enc/compress_fragment", "enc/compress_fragment_two_pass",
|
|
"enc/dictionary_hash", "enc/encode", "enc/encoder_dict", "enc/entropy_encode",
|
|
"enc/fast_log", "enc/histogram", "enc/literal_cost", "enc/memory",
|
|
"enc/metablock", "enc/static_dict", "enc/utf8_util",
|
|
];
|
|
|
|
export const brotli: Dependency = {
|
|
name: "brotli",
|
|
|
|
source: () => ({
|
|
kind: "github-archive",
|
|
repo: "google/brotli",
|
|
commit: BROTLI_COMMIT,
|
|
}),
|
|
|
|
build: cfg => {
|
|
const spec: DirectBuild = {
|
|
kind: "direct",
|
|
sources: SOURCES.map(s => `c/${s}.c`),
|
|
includes: ["c/include"],
|
|
// log2 exists everywhere we target; the cmake check only exists for
|
|
// ancient bionic. OS_* selects the <endian.h> include in platform.h;
|
|
// Windows is detected via _WIN32 directly so needs no define here.
|
|
defines: {
|
|
BROTLI_HAVE_LOG2: 1,
|
|
...(cfg.linux && { OS_LINUX: true }),
|
|
...(cfg.darwin && { OS_MACOSX: true }),
|
|
...(cfg.freebsd && { OS_FREEBSD: true }),
|
|
},
|
|
pic: true,
|
|
};
|
|
|
|
return spec;
|
|
},
|
|
|
|
provides: () => ({
|
|
libs: [],
|
|
includes: ["c/include"],
|
|
}),
|
|
};
|