Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .github/workflows/release-process-daemon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ jobs:
target: x86_64-apple-darwin
- runner: macos-15
target: aarch64-apple-darwin
- runner: ubuntu-22.04
target: aarch64-linux-android
android: true
api-level: "28"
runs-on: ${{ matrix.runner }}
env:
MACOSX_DEPLOYMENT_TARGET: "11.0"
Expand All @@ -95,15 +99,36 @@ jobs:
- name: Install musl toolchain
if: matrix.musl
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Configure Android NDK
if: matrix.android
run: |
ndk="${ANDROID_NDK_LATEST_HOME:-$ANDROID_NDK_HOME}"
test -n "$ndk" || { echo "Android NDK is not installed" >&2; exit 1; }
sysroot="$ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot"
lib="$sysroot/usr/lib/aarch64-linux-android/${{ matrix.api-level }}"
cat > "$RUNNER_TEMP/android-libc.txt" <<EOF
include_dir=$sysroot/usr/include
sys_include_dir=$sysroot/usr/include/aarch64-linux-android
crt_dir=$lib
msvc_lib_dir=
kernel32_lib_dir=
gcc_dir=$lib
darwin_sdk_dir=
EOF
{
echo "ZIG_LIBC=$RUNNER_TEMP/android-libc.txt"
echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android${{ matrix.api-level }}-clang"
} >> "$GITHUB_ENV"
- name: Install Rust target
run: rustup toolchain install 1.90.0 --profile minimal --target "${{ matrix.target }}"
- name: Install glibc baseline linker
if: endsWith(matrix.target, '-linux-gnu')
run: cargo install cargo-zigbuild --locked --version "$CARGO_ZIGBUILD_VERSION"
- name: Test service
if: matrix.android != true
run: cargo test --locked --target "${{ matrix.target }}" --lib --test service --test ownership
- name: Test CLI integration
if: runner.os != 'macOS'
if: runner.os != 'macOS' && matrix.android != true
run: cargo test --locked --target "${{ matrix.target }}" --test playground
- name: Build
run: |
Expand All @@ -120,6 +145,8 @@ jobs:
echo "Highest required glibc version: $required"
test "$(printf '%s\n' "$required" "$GNU_GLIBC_VERSION" | sort -V | tail -n 1)" = "$GNU_GLIBC_VERSION"
- name: Smoke test
# Android binaries only run on a device or emulator.
if: matrix.android != true
run: |
version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "opencode-pty") | .version')"
binary="target/${{ matrix.target }}/release/opencode-pty"
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const allTargets: {
{ os: "linux", arch: "arm64", abi: "musl" },
{ os: "linux", arch: "x64", abi: "musl" },
{ os: "linux", arch: "x64", abi: "musl", avx2: false },
{ os: "android", arch: "arm64" },
{ os: "darwin", arch: "arm64" },
{ os: "darwin", arch: "x64" },
{ os: "darwin", arch: "x64", avx2: false },
Expand Down Expand Up @@ -180,7 +181,7 @@ export default { path: file, version: ${JSON.stringify(opencodePty.version)}, sh
autoloadDotenv: false,
autoloadTsconfig: true,
autoloadPackageJson: true,
target: target.replace(binary, "bun") as Bun.Build.CompileTarget,
target: compileTarget(item) as Bun.Build.CompileTarget,
...(executablePath ? { executablePath } : {}),
outfile: path.join(outdir, name, "bin", binary),
execArgv: [
Expand Down Expand Up @@ -234,12 +235,13 @@ async function compileExecutable(item: (typeof allTargets)[number]) {
const release = process.env.BUN_COMPILE_RELEASE
if (!release) return

const platform = item.os === "win32" ? "windows" : item.os
const platform = item.os === "win32" ? "windows" : item.os === "android" ? "linux" : item.os
const name = [
"bun",
platform,
item.arch === "arm64" ? "aarch64" : item.arch,
item.abi,
item.os === "android" ? "android" : undefined,
item.avx2 === false ? "baseline" : undefined,
]
.filter(Boolean)
Expand Down Expand Up @@ -330,3 +332,9 @@ function targetName(item: (typeof allTargets)[number]) {
.filter(Boolean)
.join("-")
}

// Bun names the Android target as a Linux one with an Android suffix, unlike the npm package name.
function compileTarget(item: (typeof allTargets)[number]) {
if (item.os === "android") return "bun-linux-arm64-android"
return targetName(item).replace(binary, "bun")
}
2 changes: 1 addition & 1 deletion packages/cli/script/opencode-pty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const core = createRequire(path.resolve(import.meta.dirname, "../../core/package
const pty = createRequire(core.resolve("@opencode/pty/package.json"))

export async function resolveOpencodePty(target: Target): Promise<OpencodePtyAsset | undefined> {
if (target.platform !== "darwin" && target.platform !== "linux" && target.platform !== "win32") return undefined
if (!["darwin", "linux", "win32", "android"].includes(target.platform)) return undefined
if (target.arch !== "arm64" && target.arch !== "x64") return undefined

const suffix = [target.platform, target.arch, target.platform === "linux" ? (target.libc ?? "glibc") : undefined]
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/script/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function packDistribution(input: {
version,
license: pkg.license,
repository: { type: "git", url: "git+https://github.com/anomalyco/opencode.git" },
os: ["darwin", "linux", "win32"],
os: ["darwin", "linux", "win32", "android"],
cpu: ["arm64", "x64"],
optionalDependencies: binaries,
},
Expand Down
6 changes: 5 additions & 1 deletion packages/process-daemon/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ fn main() {
}
build.arg("--prefix").arg(&install);
build.arg("--cache-dir").arg(out.join("zig-cache"));
if env::var("HOST").as_deref() != Ok(target.as_str()) {
// Android builds always pin the target: the host is Android on Termux, but the
// API level must stay explicit so Zig does not consult getprop.
if env::var("HOST").as_deref() != Ok(target.as_str()) || target == "aarch64-linux-android" {
let zig_target = match target.as_str() {
"x86_64-unknown-linux-gnu" => "x86_64-linux-gnu",
"aarch64-unknown-linux-gnu" => "aarch64-linux-gnu",
Expand All @@ -114,6 +116,8 @@ fn main() {
"aarch64-apple-darwin" => "aarch64-macos",
"x86_64-pc-windows-msvc" => "x86_64-windows-msvc",
"aarch64-pc-windows-msvc" => "aarch64-windows-msvc",
// Pin the API level so Zig does not shell out to getprop, matching Bun's Android target.
"aarch64-linux-android" => "aarch64-linux-android.28",
_ => panic!("unsupported Ghostty target: {target}"),
};
build.arg(format!("-Dtarget={zig_target}"));
Expand Down
9 changes: 7 additions & 2 deletions packages/process-daemon/npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { createRequire } from "node:module"
import path from "node:path"

const require = createRequire(import.meta.url)
const supported = process.platform === "darwin" || process.platform === "linux" || process.platform === "win32"
const supported =
process.platform === "darwin" ||
process.platform === "linux" ||
process.platform === "win32" ||
process.platform === "android"
const arch = process.arch === "arm64" || process.arch === "x64" ? process.arch : undefined
const libc = process.platform === "linux" ? (process.report.getReport().header.glibcVersionRuntime ? "gnu" : "musl") : ""
const libc =
process.platform === "linux" ? (process.report.getReport().header.glibcVersionRuntime ? "gnu" : "musl") : ""
const suffix = [process.platform, arch, libc].filter(Boolean).join("-")

export const binaryPath =
Expand Down
3 changes: 2 additions & 1 deletion packages/process-daemon/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"@opencode/pty-linux-x64-gnu": "0.4.0",
"@opencode/pty-linux-x64-musl": "0.4.0",
"@opencode/pty-win32-arm64": "0.4.0",
"@opencode/pty-win32-x64": "0.4.0"
"@opencode/pty-win32-x64": "0.4.0",
"@opencode/pty-android-arm64": "0.4.0"
},
"publishConfig": {
"access": "public"
Expand Down
1 change: 1 addition & 0 deletions packages/process-daemon/script/npm-packages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const targets = [
{ target: "x86_64-unknown-linux-musl", platform: "linux", arch: "x64", libc: "musl", suffix: "musl" },
{ target: "aarch64-pc-windows-msvc", platform: "win32", arch: "arm64" },
{ target: "x86_64-pc-windows-msvc", platform: "win32", arch: "x64" },
{ target: "aarch64-linux-android", platform: "android", arch: "arm64" },
]

await rm(output, { recursive: true, force: true })
Expand Down
15 changes: 14 additions & 1 deletion packages/process-daemon/src/daemon/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn socket_root() -> Result<PathBuf> {

fn resolve_socket_root(directory: Option<PathBuf>, uid: u32) -> Result<PathBuf> {
let base = match directory {
None => PathBuf::from("/tmp"),
None => default_socket_base(),
Some(directory) if !directory.is_absolute() => {
bail!("OPENCODE_PTY_SOCKET_DIR must be an absolute path")
}
Expand All @@ -191,6 +191,19 @@ fn resolve_socket_root(directory: Option<PathBuf>, uid: u32) -> Result<PathBuf>
Ok(base.join(format!("opencode-pty-{uid}")))
}

fn default_socket_base() -> PathBuf {
// Android runtimes do not provide a writable /tmp; TMPDIR points at the app's
// own temporary directory (Termux sets it to $PREFIX/tmp).
#[cfg(target_os = "android")]
{
std::env::temp_dir()
}
#[cfg(not(target_os = "android"))]
{
PathBuf::from("/tmp")
}
}

fn socket_file(root: &Path, canonical_directory: &Path) -> PathBuf {
let digest = Sha256::digest(canonical_directory.as_os_str().as_bytes());
let name = digest[..16]
Expand Down
19 changes: 19 additions & 0 deletions patches/@ff-labs%2Ffff-bun@0.10.5.patch
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,22 @@ index 3b54b82d03bd5d37f3665d59c91273dc62118c1b..17bf456ea78d6b1f432d514f12eb430c
getTriple,
-} from "./platform";
+} from "./platform.js";

diff --git a/src/embedded.ts b/src/embedded.ts
--- a/src/embedded.ts
+++ b/src/embedded.ts
@@ -46,6 +46,14 @@
);
}

+ if (process.platform === "android") {
+ return importFile(
+ import(`@ff-labs/fff-bin-android-arm64/libfff_c.so`, {
+ with: { type: "file" },
+ }),
+ );
+ }
+
return null;
}

Loading