Skip to content

feat: add Bun runtime support with cross-platform binary builds#622

Draft
pcfreak30 wants to merge 4 commits intohotovo:mainfrom
pcfreak30:feat/bun-support
Draft

feat: add Bun runtime support with cross-platform binary builds#622
pcfreak30 wants to merge 4 commits intohotovo:mainfrom
pcfreak30:feat/bun-support

Conversation

@pcfreak30
Copy link
Contributor

Add comprehensive support for building and running AiderDesk as compiled Bun binaries across multiple platforms (Linux x64/arm64, macOS x64/arm64, Windows x64).

Key changes:

  • Add bunup.config.ts for multi-platform Bun binary compilation
  • Implement embedded resource system with mutex-protected I/O operations
  • Add bun-resources.ts for resource extraction, caching, and renderer file serving
  • Refactor data-manager.ts with adapter pattern supporting bun:sqlite and better-sqlite3
  • Update startup and server initialization for Bun binary environment
  • Add platform-specific binary and resource path handling
  • Add build scripts for Bun: build:bun, build:bun:all, and platform-specific targets
  • Add dependencies: bunup, @types/bun, simple-git-hooks
  • Update TypeScript configurations for Bun types and path mappings

Notes:

  • simple-git-hooks is forced in b/c bunup makes some weird devtools assumptions and errors if its not in $PATH. Added this simply to ensure no build issues.
  • A CWD workaround is required with bun and due to that all bun logic is isolated to one file and uses the mutex system to prevent race conditions with changing CWD. Probably not bulletproof, but it should defensively guard against most things.

@github-actions github-actions bot requested a review from wladimiiir January 19, 2026 01:52
@gemini-code-assist
Copy link

Summary of Changes

Hello @pcfreak30, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the application's deployment flexibility by introducing full support for the Bun runtime and its capability to produce cross-platform standalone binaries. The changes involve a complete overhaul of how resources are managed, how the database interacts with different runtimes, and how the application is built and initialized, ultimately enabling a more efficient and portable distribution model without compromising existing Electron/Node.js functionality.

Highlights

  • Bun Runtime Support: Added comprehensive support for building and running the application as compiled Bun binaries across multiple platforms (Linux x64/arm64, macOS x64/arm64, Windows x64).
  • Embedded Resource System: Implemented a new system for managing embedded resources within Bun binaries, including mutex-protected I/O operations, resource extraction to a temporary directory, and serving renderer files directly from embedded content with caching.
  • Database Adapter Pattern: Refactored the DataManager to use an adapter pattern for SQLite, allowing it to dynamically switch between bun:sqlite (for Bun runtime) and better-sqlite3 (for other Node.js environments), ensuring database compatibility across different runtimes.
  • Build System Enhancements: Integrated bunup for multi-platform Bun binary compilation and added new build scripts in package.json to facilitate Bun-specific builds, including platform-specific targets.
  • Platform-Specific Path Handling: Introduced utility functions and updated constants to dynamically determine and use correct platform-specific paths for binaries and resources, adapting to the target environment (e.g., uv and probe executables).
  • Startup and Server Initialization: Modified the application's startup sequence to include extraction of embedded resources when running as a Bun binary, and updated the server controller to serve renderer files using a custom middleware that leverages Bun's embedded resource capabilities.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive support for the Bun runtime, enabling cross-platform binary builds. The changes are extensive and well-executed. Key highlights include a new bunup.config.ts for multi-platform compilation, a robust embedded resource system in bun-resources.ts featuring a clever CWD workaround with mutex protection, and a well-designed refactoring of data-manager.ts using the adapter pattern to support both bun:sqlite and better-sqlite3. The startup logic and server initialization have also been updated effectively for the Bun environment. The overall implementation is solid. I've provided a few suggestions to enhance code cleanliness and robustness. Excellent work on this complex feature.

* @param content The content of the message.
*/
public saveMessage(id: string, type: 'tool' | 'assistant', project: string, model: string, usageReport: UsageReportData | undefined, content: unknown): void {
public async saveMessage(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function has been made async, but the callers were not updated. Consider using await or void there.

* @param to End date
* @returns Array of usage data rows
*/
public async queryUsageData(from: Date, to: Date): Promise<UsageDataRow[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify that UsageDashboard works after the change.

}

// List of text resources to extract (must match what's embedded in build script)
const textResources = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not very maintainable approach. We will need to manage this manually whenever anything changes in the resources.

const destConnectorPath = path.join(AIDER_DESK_CONNECTOR_DIR, 'connector.py');
fs.copyFileSync(sourceConnectorPath, destConnectorPath);

if (isBunBinary()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a logic in paths.ts file to determine value RESOURCE_DIR. I think the isBunBinary conditioning should go there instead.


if (fs.existsSync(sourceMcpServerDir)) {
const files = fs.readdirSync(sourceMcpServerDir);
if (isBunBinary()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to extract this as separate file with all the special start up logic for Bun.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe have helper function copyResourceFile that will decide how to copy the file, so the this file does not have to know about the Bun.

package.json Outdated
"postbuild:server": "npm rebuild",
"build": "npm run typecheck && electron-vite build && npm run build:mcp",
"build": "npm run typecheck && npm run build:renderer && npm run build:mcp",
"build:renderer": "electron-vite build",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really only renderer but the whole app with renderer and main.

tsconfig.json Outdated
"baseUrl": ".",
"paths": {
"@/*": [
"src/main/*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct in the context of tsconfig.web.json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wladimiiir this is kind of required. bunup removed needing a custom build script but I cannot reasonably get it to use a custom tsconfig that doesnt create weird build time race conditions.

I have tried and it was better to give in and put the alias in the default config.

"compilerOptions": {
"composite": true,
"types": ["electron-vite/node"],
"types": ["electron-vite/node", "bun"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have separate tsconfig.bun.json file instead to keep this clean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wladimiiir no, bunup requires the default config and I could not get it to listen otherwise... despite me RE'ing the code and figuring out where it passes the tsconfig data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wladimiiir no, bunup requires the default config and I could not get it to listen otherwise... despite me RE'ing the code and figuring out where it passes the tsconfig data.

This problem seems to be resolved and im reviewing the other issues.

Copy link
Contributor

@wladimiiir wladimiiir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments.

Add comprehensive support for building and running AiderDesk as compiled Bun binaries across multiple platforms (Linux x64/arm64, macOS x64/arm64, Windows x64).

Key changes:
- Add bunup.config.ts for multi-platform Bun binary compilation
- Implement embedded resource system with mutex-protected I/O operations
- Add bun-resources.ts for resource extraction, caching, and renderer file serving
- Refactor data-manager.ts with adapter pattern supporting bun:sqlite and better-sqlite3
- Update startup and server initialization for Bun binary environment
- Add platform-specific binary and resource path handling
- Add build scripts for Bun: build:bun, build:bun:all, and platform-specific targets
- Add dependencies: bunup, @types/bun, simple-git-hooks
- Update TypeScript configurations for Bun types and path mappings
- Remove unused readFileSync import from build config
- Add error logging to catch block for better debugging
- Simplify typeAssertions in database adapters to use ISqliteStatement interface
- Extract Bun startup logic to dedicated bun-startup.ts module
- Implement dynamic resource discovery using glob instead of hardcoded lists
- Add fallback resource mechanism for reliability
- Create copyResourceFile helper to abstract Bun vs filesystem access
- Add setupMcpServerForBun and setupAiderConnectorForBun helpers
- Fix async dataManager.init() call with proper await
- Fix async dataManager.saveMessage() calls (await for assistant, void for tool)
- Rename build:renderer to build:app for clarity
- Remove duplicate code from start-up.ts
- Fix all func-style linting errors by converting to arrow expressions
- Fix @typescript-eslint/no-explicit-any errors with proper type interfaces
@pcfreak30 pcfreak30 marked this pull request as draft January 29, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants