PORTNAME= bun
DISTVERSIONPREFIX= bun-v
DISTVERSION= 1.3.13-93
DISTVERSIONSUFFIX= -g146a674cf6
CATEGORIES= lang
MASTER_SITES= GH \
https://github.com/oven-sh/zig/releases/download/autobuild-04e7f6ac1e009525bc00934f20199c68f04e0a24/:ovenzig \
https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_VERSION}/:webkit \
https://nodejs.org/dist/v${NODE_VERSION}/:nodejshdr \
LOCAL/yuri/:bootstrap
DISTFILES= bootstrap-x86_64-linux-musl.zip:ovenzig \
bun-webkit-freebsd-amd64.tar.gz:webkit \
node-v${NODE_VERSION}-headers.tar.gz:nodejshdr \
bun-1.3.13-93-bootstrap:bootstrap
DIST_SUBDIR= ${PORTNAME}
# Only auto-extract the GitHub source tarball; everything else is handled in post-extract.
EXTRACT_ONLY= ${DISTNAME}${EXTRACT_SUFX}
MAINTAINER= [email protected]
COMMENT= JavaScript runtime, bundler, test runner, and package manager
WWW= https://bun.com/ \
https://github.com/oven-sh/bun
LICENSE= LGPL20
ONLY_FOR_ARCHS= amd64
ONLY_FOR_ARCHS_REASON= bootstrap binary is only available for amd64 for now
# do-fetch requires npm (node_modules build) and cargo (lolhtml vendor)
FETCH_DEPENDS= ${LOCALBASE}/bin/npm:www/npm-node24 \
git:devel/git \
cargo:lang/rust \
${LOCALBASE}/llvm21/bin/clang++:devel/llvm21 \
cmake:devel/cmake-core \
ninja:devel/ninja \
${LOCALBASE}/bin/node:www/node24
BUILD_DEPENDS= ${LOCALBASE}/llvm21/bin/clang++:devel/llvm21 \
cmake:devel/cmake-core \
git:devel/git \
ninja:devel/ninja \
cargo:lang/rust \
${LOCALBASE}/bin/node:www/node24 \
${LOCALBASE}/bin/npm:www/npm-node24
TEST_DEPENDS= bash:shells/bash
USES= shebangfix
USE_GITHUB= yes
GH_ACCOUNT= oven-sh
SHEBANG_FILES= test/regression/issue/18239/data-generator.sh
# WebKit/JavaScriptCore FreeBSD prebuilt
WEBKIT_VERSION= bdf6aab38a9c6f99df3fd1486406ab6b74180fbb
WEBKIT_SHORT= bdf6aab38a9c6f99
# Node.js headers (official tarball from nodejs.org; do-fetch trims unused dirs)
NODE_VERSION= 24.3.0
# Custom tarballs are built by do-fetch and stored in DD.
# They are NOT listed in DISTFILES so checksum phase does not verify them.
# Dep tarball cache names and their upstream GitHub URLs.
# Names are {depname}-{sha256(url)[0:16]}.tar.gz (computed by bun's fetch-cli.ts).
# Used by do-fetch to pre-populate the bun dep tarballs cache.
_BUN_DEP_TARBALLS= \
boringssl-5e15ff9594809574.tar.gz:https://github.com/oven-sh/boringssl/archive/0c5fce43b7ed5eb6001487ee48ac65766f5ddcd1.tar.gz \
brotli-723494d4c3a9902a.tar.gz:https://github.com/google/brotli/archive/v1.1.0.tar.gz \
cares-4e43539b43c0f4ae.tar.gz:https://github.com/c-ares/c-ares/archive/3ac47ee46edd8ea40370222f91613fc16c434853.tar.gz \
hdrhistogram-97084f213075a65e.tar.gz:https://github.com/HdrHistogram/HdrHistogram_c/archive/be60a9987ee48d0abf0d7b6a175bad8d6c1585d1.tar.gz \
highway-a10c8937e1b920ad.tar.gz:https://github.com/google/highway/archive/ac0d5d297b13ab1b89f48484fc7911082d76a93f.tar.gz \
libarchive-4296b191210d6b1b.tar.gz:https://github.com/libarchive/libarchive/archive/ded82291ab41d5e355831b96b0e1ff49e24d8939.tar.gz \
libdeflate-ce0e2d9805b30dcc.tar.gz:https://github.com/ebiggers/libdeflate/archive/c8c56a20f8f621e6a966b716b31f1dedab6a41e3.tar.gz \
lolhtml-929339b1d898e66b.tar.gz:https://github.com/cloudflare/lol-html/archive/77127cd2b8545998756e8d64e36ee2313c4bb312.tar.gz \
lshpack-73e0c55d12ea4fc2.tar.gz:https://github.com/litespeedtech/ls-hpack/archive/8905c024b6d052f083a3d11d0a169b3c2735c8a1.tar.gz \
mimalloc-9e61bdd994e99463.tar.gz:https://github.com/oven-sh/mimalloc/archive/dbbb9a0819d00d521f9f58ad4d0a336efa4ce53a.tar.gz \
picohttpparser-fad59b16ad4752cc.tar.gz:https://github.com/h2o/picohttpparser/archive/066d2b1e9ab820703db0837a7255d92d30f0c9f5.tar.gz \
zlib-655c6ecdb6fc9cd5.tar.gz:https://github.com/zlib-ng/zlib-ng/archive/12731092979c6d07f42da27da673a9f6c7b13586.tar.gz \
zstd-e010993a24072468.tar.gz:https://github.com/facebook/zstd/archive/f8745da6ff1ad1e7bab384bd1f9d742439278e99.tar.gz
DD= ${DISTDIR}/${DIST_SUBDIR}
BUN_CACHE_DIR= ${WRKDIR}/bun-cache
BUN_ZIG_DIR= ${WRKDIR}/oven-zig
BUN_BUILD_DIR= ${WRKSRC}/build/release
PLIST_FILES= bin/${PORTNAME}
# do-fetch: download the standard distfiles, then build the 3 custom archives
# (node_modules, dep tarballs, cargo vendor) if they are not already cached.
# All files land in ${DD} so make checksum and poudriere can reuse them.
do-fetch:
@${MKDIR} ${DD}
# Fetch directly-downloadable distfiles (GH0 uses DEFAULT master site, no group suffix)
@${SETENV} ${_DO_FETCH_ENV} ${_MASTER_SITES_ENV} dp_SITE_FLAVOR=MASTER \
${SH} ${SCRIPTSDIR}/do-fetch.sh \
${DISTNAME}${EXTRACT_SUFX} \
${DISTFILES:M*\:ovenzig} \
${DISTFILES:M*\:webkit} \
${DISTFILES:M*\:nodejshdr} \
${DISTFILES:M*\:bootstrap}
# Build bun-node-modules tarball (npm install with workspace: → file: fixes).
# Uses deterministic tar so the checksum is reproducible across builds.
@if ! [ -f "${DD}/bun-node-modules-${DISTVERSION}.tar.gz" ]; then \
${ECHO_CMD} "===> Building bun-node-modules-${DISTVERSION}.tar.gz" && \
_NTmp=$$(mktemp -d /tmp/bun-nmod.XXXXXX) && \
bsdtar xzf ${DD}/${DISTNAME}${EXTRACT_SUFX} -C $$_NTmp && \
_NSrc=$$_NTmp/${WRKSRC:T} && \
${SED} -i '' \
's|"@types/bun": "workspace:\*"|"@types/bun": "file:packages/@types/bun"|' \
$$_NSrc/package.json && \
${SED} -i '' \
's|"bun-types": "workspace:"|"bun-types": "file:../bun-types"|' \
$$_NSrc/packages/@types/bun/package.json && \
(cd $$_NSrc && ${LOCALBASE}/bin/npm install --ignore-scripts) && \
(cd $$_NSrc/packages/bun-error && \
${LOCALBASE}/bin/npm install --ignore-scripts) && \
(cd $$_NSrc/src/node-fallbacks && \
${LOCALBASE}/bin/npm install --ignore-scripts) && \
${FIND} $$_NSrc/node_modules \
$$_NSrc/packages/bun-error/node_modules \
$$_NSrc/src/node-fallbacks/node_modules \
-exec ${TOUCH} -h -d 1970-01-01T00:00:00Z {} \; && \
(cd $$_NSrc && \
${FIND} node_modules packages/bun-error/node_modules \
src/node-fallbacks/node_modules -print0 \
| LC_ALL=C ${SORT} -z \
| ${SETENV} -i ${TAR} czf ${DD}/bun-node-modules-${DISTVERSION}.tar.gz \
--format=cpio --gid 0 --uid 0 --options gzip:!timestamp \
--no-recursion --null -T -) && \
${RM} -rf $$_NTmp; \
fi
# Build bun-dep-tarballs + bun-cargo-vendor-lolhtml tarballs.
# Uses deterministic tar so checksums are reproducible across builds.
@if ! [ -f "${DD}/bun-dep-tarballs-${DISTVERSION}.tar.gz" ] || \
! [ -f "${DD}/bun-cargo-vendor-lolhtml-${DISTVERSION}.tar.gz" ]; then \
${ECHO_CMD} "===> Downloading bun dep tarballs" && \
_DTmp=$$(mktemp -d /tmp/bun-dtp.XXXXXX) && \
${MKDIR} $$_DTmp/tarballs && \
for _tu in ${_BUN_DEP_TARBALLS}; do \
_tc=$${_tu%%:*}; _url=$${_tu#*:}; \
if ! [ -f "$$_DTmp/tarballs/$$_tc" ]; then \
${FETCH_CMD} ${FETCH_BEFORE_ARGS} $$_url ${FETCH_AFTER_ARGS} \
-o $$_DTmp/tarballs/$$_tc || exit 1; \
fi; \
done && \
if ! [ -f "${DD}/bun-dep-tarballs-${DISTVERSION}.tar.gz" ]; then \
${ECHO_CMD} "===> Packaging bun-dep-tarballs-${DISTVERSION}.tar.gz" && \
( cd $$_DTmp && \
${FIND} tarballs -exec ${TOUCH} -h -d 1970-01-01T00:00:00Z {} \; && \
${FIND} tarballs -print0 \
| LC_ALL=C ${SORT} -z \
| ${SETENV} -i ${TAR} czf ${DD}/bun-dep-tarballs-${DISTVERSION}.tar.gz \
--format=cpio --gid 0 --uid 0 --options gzip:!timestamp \
--no-recursion --null -T - ); \
fi && \
if ! [ -f "${DD}/bun-cargo-vendor-lolhtml-${DISTVERSION}.tar.gz" ]; then \
${ECHO_CMD} "===> Vendoring lolhtml Rust crates" && \
_LTmp=$$(mktemp -d /tmp/bun-lol.XXXXXX) && \
bsdtar xzf $$_DTmp/tarballs/lolhtml-929339b1d898e66b.tar.gz \
-C $$_LTmp --strip-components 1 && \
(cd $$_LTmp/c-api && \
${SETENV} HOME=$$_LTmp \
${LOCALBASE}/bin/cargo vendor vendor) && \
${FIND} $$_LTmp/c-api/vendor -exec ${TOUCH} -h -d 1970-01-01T00:00:00Z {} \; && \
( cd $$_LTmp/c-api && \
${FIND} vendor -print0 \
| LC_ALL=C ${SORT} -z \
| ${SETENV} -i ${TAR} czf ${DD}/bun-cargo-vendor-lolhtml-${DISTVERSION}.tar.gz \
--format=cpio --gid 0 --uid 0 --options gzip:!timestamp \
--no-recursion --null -T - ) && \
${RM} -rf $$_LTmp; \
fi && \
${RM} -rf $$_DTmp; \
fi
post-extract:
# Set up bun cache directory structure
@${MKDIR} ${BUN_CACHE_DIR}/tarballs
# Extract oven-sh/zig fork (Linux binary, via linux compat)
@${MKDIR} ${BUN_ZIG_DIR}
@cd ${BUN_ZIG_DIR} && bsdtar -xf ${DD}/bootstrap-x86_64-linux-musl.zip
@${CHMOD} +x ${BUN_ZIG_DIR}/bootstrap-x86_64-linux-musl/zig
# Install pre-built native FreeBSD bun bootstrap binary
@${MKDIR} ${WRKDIR}/bun-bootstrap
@${CP} ${DD}/bun-1.3.13-93-bootstrap ${WRKDIR}/bun-bootstrap/bun
@${CHMOD} +x ${WRKDIR}/bun-bootstrap/bun
# Extract WebKit prebuilt into cache
@${MKDIR} ${BUN_CACHE_DIR}/webkit-${WEBKIT_SHORT}-freebsd
@tar xzf ${DD}/bun-webkit-freebsd-amd64.tar.gz \
-C ${BUN_CACHE_DIR}/webkit-${WEBKIT_SHORT}-freebsd \
--strip-components 1
@${ECHO_CMD} "${WEBKIT_VERSION}" > \
${BUN_CACHE_DIR}/webkit-${WEBKIT_SHORT}-freebsd/.identity
# Extract dep tarballs into cache
@tar xzf ${DD}/bun-dep-tarballs-${DISTVERSION}.tar.gz \
-C ${BUN_CACHE_DIR}
# Extract vendored Rust crates for lolhtml
@${MKDIR} ${WRKDIR}/cargo-vendor-lolhtml
@tar xzf ${DD}/bun-cargo-vendor-lolhtml-${DISTVERSION}.tar.gz \
-C ${WRKDIR}/cargo-vendor-lolhtml
# Configure cargo to use vendored sources (via CARGO_HOME config)
@${MKDIR} ${WRKDIR}/.cargo
@${PRINTF} '[source.crates-io]\nreplace-with = "vendored-sources"\n\n[source.vendored-sources]\ndirectory = "%s/vendor"\n' \
${WRKDIR}/cargo-vendor-lolhtml > ${WRKDIR}/.cargo/config.toml
# Extract nodejs headers into bun cache and remove dirs bun doesn't need
@${MKDIR} ${BUN_CACHE_DIR}/nodejs-headers-${NODE_VERSION}
@tar xzf ${DD}/node-v${NODE_VERSION}-headers.tar.gz \
-C ${BUN_CACHE_DIR}/nodejs-headers-${NODE_VERSION} \
--strip-components 1
@${RM} -rf \
${BUN_CACHE_DIR}/nodejs-headers-${NODE_VERSION}/include/node/openssl \
${BUN_CACHE_DIR}/nodejs-headers-${NODE_VERSION}/include/node/uv \
${BUN_CACHE_DIR}/nodejs-headers-${NODE_VERSION}/include/node/uv.h
@${ECHO_CMD} "${NODE_VERSION}" > \
${BUN_CACHE_DIR}/nodejs-headers-${NODE_VERSION}/.identity
# Extract node_modules into WRKSRC
@tar xzf ${DD}/bun-node-modules-${DISTVERSION}.tar.gz \
-C ${WRKSRC}
do-build:
@cd ${WRKSRC} && \
${SETENV} PATH=${LOCALBASE}/llvm21/bin:${LOCALBASE}/bin:/usr/bin:/bin \
BUN_ZIG_PATH=${BUN_ZIG_DIR}/bootstrap-x86_64-linux-musl \
BUN_HOST_OS=freebsd \
FREEBSD_SYSROOT=/ \
CARGO_HOME=${WRKDIR}/.cargo \
GIT_SHA=${DISTVERSIONSUFFIX:S/-g//} \
${WRKDIR}/bun-bootstrap/bun scripts/build.ts \
--os=freebsd \
--cacheDir=${BUN_CACHE_DIR} \
--buildDir=${BUN_BUILD_DIR} \
--profile=release \
-j${MAKE_JOBS_NUMBER}
do-install:
${INSTALL_PROGRAM} ${BUN_BUILD_DIR}/bun ${STAGEDIR}${PREFIX}/bin/
do-test:
@${ECHO_CMD} "==> Running Bun version check..."
${STAGEDIR}${PREFIX}/bin/bun --version
@${ECHO_CMD} "==> Installing test dependencies..."
cd ${WRKSRC}/test && ${STAGEDIR}${PREFIX}/bin/bun install \
--frozen-lockfile --ignore-scripts
@${ECHO_CMD} "==> Running Bun regression tests..."
cd ${WRKSRC} && ${STAGEDIR}${PREFIX}/bin/bun test --timeout 120000 --parallel 1
.include <bsd.port.mk>