Skip to content

使用 --compile 標志編譯你的可執行文件。

sh
bun build --compile ./path/to/entry.ts --outfile myapp

列出可用的簽名身份。其中一個將是你傳遞給 codesign 命令的簽名身份。此命令需要 macOS。

sh
security find-identity -v -p codesigning
txt
1. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "Developer ID Application: Your Name (ZZZZZZZZZZ)"
   1 valid identities found

可選,但推薦:創建一個 entitlements.plist 文件,其中包含 JavaScript 引擎正常工作所需的權限。

xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.disable-executable-page-protection</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
</dict>
</plist>

使用 codesign 命令對你的可執行文件進行簽名,並驗證其是否有效。

bash
codesign --entitlements entitlements.plist -vvvv --deep --sign "XXXXXXXXXX" ./myapp --force
codesign -vvv --verify ./myapp

有關 macOS 代碼簽名的更多信息,請參閱 Apple 的代碼簽名文檔。有關使用 Bun 創建單文件可執行文件的詳細信息,請參閱 獨立可執行文件。本指南需要 Bun v1.2.4 或更高版本。

Bun學習網由www.bunjs.com.cn整理維護