使用 --compile
標記編譯您的可執行檔。
bun build --compile ./path/to/entry.ts --outfile myapp
列出您可用的簽署身分。其中一個將會是您傳遞給 codesign
命令的簽署身分。此命令需要 macOS。
security find-identity -v -p codesigning
1. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "Developer ID Application: Your Name (ZZZZZZZZZZ)"
1 valid identities found
可選但建議:建立一個 entitlements.plist
檔案,其中包含 JavaScript 引擎正常運作所需的權限。
<?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
命令簽署您的可執行檔,並驗證它是否運作。
codesign --entitlements entitlements.plist -vvvv --deep --sign "XXXXXXXXXX" ./myapp --force
codesign -vvv --verify ./myapp
如需 macOS 程式碼簽署的更多資訊,請參閱Apple 的程式碼簽署文件。如需使用 Bun 建立單一檔案可執行檔的詳細資訊,請參閱獨立可執行檔。本指南需要 Bun v1.2.4 或更新版本。