full-build-macos.sh 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. #!/bin/bash
  2. ##############################################################################
  3. # macOS full build script
  4. ##############################################################################
  5. #
  6. # This script contains all steps necessary to:
  7. #
  8. # * Build OBS with all default plugins and dependencies
  9. # * Create a macOS application bundle
  10. # * Code-sign the macOS application-bundle
  11. # * Package a macOS installation image
  12. # * Notarize macOS application-bundle and/or installation image
  13. #
  14. # Parameters:
  15. # -b: Create macOS bundle
  16. # -d: Skip dependency checks
  17. # -p: Create macOS distribution image
  18. # -n: Notarize macOS app and disk image (implies bundling)
  19. # -s: Skip the build process (useful for bundling/packaging only)
  20. # -h: Print usage help
  21. #
  22. # Environment Variables (optional):
  23. # MACOS_DEPS_VERSION : Pre-compiled macOS dependencies version
  24. # MACOS_CEF_BUILD_VERSION : Chromium Embedded Framework version
  25. # VLC_VERISON : VLC version
  26. # SPARKLE_VERSION : Sparke Framework version
  27. # BUILD_DIR : Alternative directory to build OBS in
  28. #
  29. ##############################################################################
  30. # Halt on errors
  31. set -eE
  32. ## SET UP ENVIRONMENT ##
  33. PRODUCT_NAME="OBS-Studio"
  34. CHECKOUT_DIR="$(/usr/bin/git rev-parse --show-toplevel)"
  35. DEPS_BUILD_DIR="${CHECKOUT_DIR}/../obs-build-dependencies"
  36. BUILD_DIR="${BUILD_DIR:-build}"
  37. BUILD_CONFIG=${BUILD_CONFIG:-RelWithDebInfo}
  38. CI_SCRIPTS="${CHECKOUT_DIR}/CI/scripts/macos"
  39. CI_WORKFLOW="${CHECKOUT_DIR}/.github/workflows/main.yml"
  40. CI_MACOS_CEF_VERSION=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+MACOS_CEF_BUILD_VERSION: '([0-9]+)'/\1/p")
  41. CI_DEPS_VERSION=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+MACOS_DEPS_VERSION: '([0-9\-]+)'/\1/p")
  42. CI_VLC_VERSION=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+VLC_VERSION: '([0-9\.]+)'/\1/p")
  43. CI_SPARKLE_VERSION=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+SPARKLE_VERSION: '([0-9\.]+)'/\1/p")
  44. CI_QT_VERSION=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+QT_VERSION: '([0-9\.]+)'/\1/p" | /usr/bin/head -1)
  45. CI_MIN_MACOS_VERSION=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+MIN_MACOS_VERSION: '([0-9\.]+)'/\1/p")
  46. NPROC="${NPROC:-$(sysctl -n hw.ncpu)}"
  47. CURRENT_ARCH=$(uname -m)
  48. BUILD_DEPS=(
  49. "obs-deps ${MACOS_DEPS_VERSION:-${CI_DEPS_VERSION}}"
  50. "qt-deps ${QT_VERSION:-${CI_QT_VERSION}} ${MACOS_DEPS_VERSION:-${CI_DEPS_VERSION}}"
  51. "cef ${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}"
  52. "vlc ${VLC_VERSION:-${CI_VLC_VERSION}}"
  53. "sparkle ${SPARKLE_VERSION:-${CI_SPARKLE_VERSION}}"
  54. )
  55. if [ -n "${TERM-}" ]; then
  56. COLOR_RED=$(/usr/bin/tput setaf 1)
  57. COLOR_GREEN=$(/usr/bin/tput setaf 2)
  58. COLOR_BLUE=$(/usr/bin/tput setaf 4)
  59. COLOR_ORANGE=$(/usr/bin/tput setaf 3)
  60. COLOR_RESET=$(/usr/bin/tput sgr0)
  61. else
  62. COLOR_RED=""
  63. COLOR_GREEN=""
  64. COLOR_BLUE=""
  65. COLOR_ORANGE=""
  66. COLOR_RESET=""
  67. fi
  68. MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)"
  69. MACOS_MAJOR="$(/bin/echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 1)"
  70. MACOS_MINOR="$(/bin/echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 2)"
  71. ## DEFINE UTILITIES ##
  72. hr() {
  73. /bin/echo "${COLOR_BLUE}[${PRODUCT_NAME}] ${1}${COLOR_RESET}"
  74. }
  75. step() {
  76. /bin/echo "${COLOR_GREEN} + ${1}${COLOR_RESET}"
  77. }
  78. info() {
  79. /bin/echo "${COLOR_ORANGE} + ${1}${COLOR_RESET}"
  80. }
  81. error() {
  82. /bin/echo "${COLOR_RED} + ${1}${COLOR_RESET}"
  83. }
  84. exists() {
  85. /usr/bin/command -v "$1" >/dev/null 2>&1
  86. }
  87. ensure_dir() {
  88. [[ -n "${1}" ]] && /bin/mkdir -p "${1}" && builtin cd "${1}"
  89. }
  90. cleanup() {
  91. /bin/rm -rf "${CHECKOUT_DIR}/${BUILD_DIR}/settings.json"
  92. unset CODESIGN_IDENT
  93. unset CODESIGN_IDENT_USER
  94. unset CODESIGN_IDENT_PASS
  95. }
  96. caught_error() {
  97. error "ERROR during build step: ${1}"
  98. cleanup
  99. exit 1
  100. }
  101. ## CHECK AND INSTALL DEPENDENCIES ##
  102. check_macos_version() {
  103. MIN_VERSION=${MIN_MACOS_VERSION:-${CI_MIN_MACOS_VERSION}}
  104. MIN_MAJOR=$(/bin/echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 1)
  105. MIN_MINOR=$(/bin/echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 2)
  106. if [ "${MACOS_MAJOR}" -lt "11" ] && [ "${MACOS_MINOR}" -lt "${MIN_MINOR}" ]; then
  107. error "WARNING: Minimum required macOS version is ${MIN_VERSION}, but running on ${MACOS_VERSION}"
  108. fi
  109. }
  110. install_homebrew_deps() {
  111. if ! exists brew; then
  112. error "Homebrew not found - please install homebrew (https://brew.sh)"
  113. exit 1
  114. fi
  115. if [ -d /usr/local/opt/[email protected] ]; then
  116. brew uninstall [email protected]
  117. brew untap local/openssl
  118. fi
  119. if [ -d /usr/local/opt/[email protected] ]; then
  120. brew uninstall [email protected]
  121. brew untap local/python2
  122. fi
  123. brew bundle --file "${CI_SCRIPTS}/Brewfile"
  124. check_curl
  125. }
  126. check_curl() {
  127. if [ "${MACOS_MAJOR}" -lt "11" ] && [ "${MACOS_MINOR}" -lt "15" ]; then
  128. if [ ! -d /usr/local/opt/curl ]; then
  129. step "Installing Homebrew curl.."
  130. brew install curl
  131. fi
  132. export CURLCMD="/usr/local/opt/curl/bin/curl"
  133. else
  134. export CURLCMD="curl"
  135. fi
  136. }
  137. check_ccache() {
  138. export PATH="/usr/local/opt/ccache/libexec:${PATH}"
  139. CCACHE_STATUS=$(ccache -s >/dev/null 2>&1 && /bin/echo "CCache available." || /bin/echo "CCache is not available.")
  140. info "${CCACHE_STATUS}"
  141. }
  142. install_obs-deps() {
  143. hr "Setting up pre-built macOS OBS dependencies v${1}"
  144. ensure_dir "${DEPS_BUILD_DIR}"
  145. step "Download..."
  146. ${CURLCMD} --progress-bar -L -C - -O https://github.com/obsproject/obs-deps/releases/download/${1}/macos-deps-${CURRENT_ARCH}-${1}.tar.gz
  147. step "Unpack..."
  148. /usr/bin/tar -xf "./macos-deps-${CURRENT_ARCH}-${1}.tar.gz" -C /tmp
  149. }
  150. install_qt-deps() {
  151. hr "Setting up pre-built dependency QT v${1}"
  152. ensure_dir "${DEPS_BUILD_DIR}"
  153. step "Download..."
  154. ${CURLCMD} --progress-bar -L -C - -O https://github.com/obsproject/obs-deps/releases/download/${2}/macos-qt-${1}-${CURRENT_ARCH}-${2}.tar.gz
  155. step "Unpack..."
  156. /usr/bin/tar -xf ./macos-qt-${1}-${CURRENT_ARCH}-${2}.tar.gz -C /tmp
  157. /usr/bin/xattr -r -d com.apple.quarantine /tmp/obsdeps
  158. }
  159. install_vlc() {
  160. hr "Setting up dependency VLC v${1}"
  161. ensure_dir "${DEPS_BUILD_DIR}"
  162. step "Download..."
  163. ${CURLCMD} --progress-bar -L -C - -O https://downloads.videolan.org/vlc/${1}/vlc-${1}.tar.xz
  164. step "Unpack ..."
  165. /usr/bin/tar -xf vlc-${1}.tar.xz
  166. }
  167. install_sparkle() {
  168. hr "Setting up dependency Sparkle v${1} (might prompt for password)"
  169. ensure_dir "${DEPS_BUILD_DIR}/sparkle"
  170. step "Download..."
  171. ${CURLCMD} --progress-bar -L -C - -o sparkle.tar.bz2 https://github.com/sparkle-project/Sparkle/releases/download/${1}/Sparkle-${1}.tar.bz2
  172. step "Unpack..."
  173. /usr/bin/tar -xf ./sparkle.tar.bz2
  174. step "Copy to destination..."
  175. if [ -d /Library/Frameworks/Sparkle.framework/ ]; then
  176. info "Warning - Sparkle framework already found in /Library/Frameworks"
  177. else
  178. sudo /bin/cp -R ./Sparkle.framework/ /Library/Frameworks/Sparkle.framework/
  179. fi
  180. }
  181. install_cef() {
  182. hr "Building dependency CEF v${1}"
  183. ensure_dir "${DEPS_BUILD_DIR}"
  184. step "Download..."
  185. ${CURLCMD} --progress-bar -L -C - -O https://cdn-fastly.obsproject.com/downloads/cef_binary_${1}_macosx64.tar.bz2
  186. step "Unpack..."
  187. /usr/bin/tar -xf ./cef_binary_${1}_macosx64.tar.bz2
  188. cd ./cef_binary_${1}_macosx64
  189. step "Fix tests..."
  190. /usr/bin/sed -i '.orig' '/add_subdirectory(tests\/ceftests)/d' ./CMakeLists.txt
  191. /usr/bin/sed -i '.orig' 's/"'$(test "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 && echo "10.9" || echo "10.10")'"/"'${MIN_MACOS_VERSION:-${CI_MIN_MACOS_VERSION}}'"/' ./cmake/cef_variables.cmake
  192. ensure_dir ./build
  193. step "Run CMAKE..."
  194. cmake \
  195. -DCMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++ -Wno-deprecated-declarations"\
  196. -DCMAKE_EXE_LINKER_FLAGS="-std=c++11 -stdlib=libc++"\
  197. -DCMAKE_OSX_DEPLOYMENT_TARGET=${MIN_MACOS_VERSION:-${CI_MIN_MACOS_VERSION}} \
  198. ..
  199. step "Build..."
  200. /usr/bin/make -j${NPROC}
  201. if [ ! -d libcef_dll ]; then /bin/mkdir libcef_dll; fi
  202. }
  203. ## CHECK AND INSTALL PACKAGING DEPENDENCIES ##
  204. install_dmgbuild() {
  205. if ! exists dmgbuild; then
  206. if exists "pip3"; then
  207. PIPCMD="pip3"
  208. elif exists "pip"; then
  209. PIPCMD="pip"
  210. else
  211. error "Pip not found - please install pip via 'python -m ensurepip'"
  212. exit 1
  213. fi
  214. ${PIPCMD} install dmgbuild
  215. fi
  216. }
  217. ## OBS BUILD FROM SOURCE ##
  218. configure_obs_build() {
  219. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  220. CUR_DATE=$(/bin/date +"%Y-%m-%d@%H%M%S")
  221. NIGHTLY_DIR="${CHECKOUT_DIR}/nightly-${CUR_DATE}"
  222. PACKAGE_NAME=$(/usr/bin/find . -name "*.dmg")
  223. if [ -d ./OBS.app ]; then
  224. ensure_dir "${NIGHTLY_DIR}"
  225. /bin/mv "../${BUILD_DIR}/OBS.app" .
  226. info "You can find OBS.app in ${NIGHTLY_DIR}"
  227. fi
  228. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  229. if ([ -n "${PACKAGE_NAME}" ] && [ -f ${PACKAGE_NAME} ]); then
  230. ensure_dir "${NIGHTLY_DIR}"
  231. /bin/mv "../${BUILD_DIR}/$(basename "${PACKAGE_NAME}")" .
  232. info "You can find ${PACKAGE_NAME} in ${NIGHTLY_DIR}"
  233. fi
  234. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  235. hr "Run CMAKE for OBS..."
  236. cmake -DENABLE_SPARKLE_UPDATER=ON \
  237. -DCMAKE_OSX_DEPLOYMENT_TARGET=${MIN_MACOS_VERSION:-${CI_MIN_MACOS_VERSION}} \
  238. -DQTDIR="/tmp/obsdeps" \
  239. -DSWIGDIR="/tmp/obsdeps" \
  240. -DDepsPath="/tmp/obsdeps" \
  241. -DVLCPath="${DEPS_BUILD_DIR}/vlc-${VLC_VERSION:-${CI_VLC_VERSION}}" \
  242. -DBUILD_BROWSER=ON \
  243. -DBROWSER_LEGACY="$(test "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 && echo "ON" || echo "OFF")" \
  244. -DWITH_RTMPS=ON \
  245. -DCEF_ROOT_DIR="${DEPS_BUILD_DIR}/cef_binary_${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}_macosx64" \
  246. -DCMAKE_BUILD_TYPE="${BUILD_CONFIG}" \
  247. ..
  248. }
  249. run_obs_build() {
  250. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  251. hr "Build OBS..."
  252. /usr/bin/make -j${NPROC}
  253. }
  254. ## OBS BUNDLE AS MACOS APPLICATION ##
  255. bundle_dylibs() {
  256. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  257. if [ ! -d ./OBS.app ]; then
  258. error "No OBS.app bundle found"
  259. exit 1
  260. fi
  261. hr "Bundle dylibs for macOS application"
  262. step "Run dylibBundler.."
  263. BUNDLE_PLUGINS=(
  264. ./OBS.app/Contents/PlugIns/coreaudio-encoder.so
  265. ./OBS.app/Contents/PlugIns/decklink-ouput-ui.so
  266. ./OBS.app/Contents/PlugIns/decklink-captions.so
  267. ./OBS.app/Contents/PlugIns/frontend-tools.so
  268. ./OBS.app/Contents/PlugIns/image-source.so
  269. ./OBS.app/Contents/PlugIns/mac-avcapture.so
  270. ./OBS.app/Contents/PlugIns/mac-capture.so
  271. ./OBS.app/Contents/PlugIns/mac-decklink.so
  272. ./OBS.app/Contents/PlugIns/mac-syphon.so
  273. ./OBS.app/Contents/PlugIns/mac-vth264.so
  274. ./OBS.app/Contents/PlugIns/mac-virtualcam.so
  275. ./OBS.app/Contents/PlugIns/obs-browser.so
  276. ./OBS.app/Contents/PlugIns/obs-ffmpeg.so
  277. ./OBS.app/Contents/PlugIns/obs-filters.so
  278. ./OBS.app/Contents/PlugIns/obs-transitions.so
  279. ./OBS.app/Contents/PlugIns/obs-vst.so
  280. ./OBS.app/Contents/PlugIns/rtmp-services.so
  281. ./OBS.app/Contents/MacOS/obs-ffmpeg-mux
  282. ./OBS.app/Contents/MacOS/obslua.so
  283. ./OBS.app/Contents/MacOS/_obspython.so
  284. ./OBS.app/Contents/PlugIns/obs-x264.so
  285. ./OBS.app/Contents/PlugIns/text-freetype2.so
  286. ./OBS.app/Contents/PlugIns/obs-outputs.so
  287. ./OBS.app/Contents/PlugIns/aja.so
  288. ./OBS.app/Contents/PlugIns/aja-output-ui.so
  289. )
  290. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  291. "${CI_SCRIPTS}/app/dylibbundler" -cd -of -a ./OBS.app -q -f \
  292. -s ./OBS.app/Contents/MacOS \
  293. -s "${DEPS_BUILD_DIR}/sparkle/Sparkle.framework" \
  294. -s ./rundir/${BUILD_CONFIG}/bin/ \
  295. $(echo "${BUNDLE_PLUGINS[@]/#/-x }")
  296. else
  297. "${CI_SCRIPTS}/app/dylibbundler" -cd -of -a ./OBS.app -q -f \
  298. -s ./OBS.app/Contents/MacOS \
  299. -s "${DEPS_BUILD_DIR}/sparkle/Sparkle.framework" \
  300. -s ./rundir/${BUILD_CONFIG}/bin/ \
  301. $(echo "${BUNDLE_PLUGINS[@]/#/-x }") \
  302. -x ./OBS.app/Contents/PlugIns/obs-browser-page
  303. fi
  304. step "Move libobs-opengl to final destination"
  305. if [ -f "./libobs-opengl/libobs-opengl.so" ]; then
  306. /bin/cp ./libobs-opengl/libobs-opengl.so ./OBS.app/Contents/Frameworks
  307. else
  308. /bin/cp ./libobs-opengl/${BUILD_CONFIG}/libobs-opengl.so ./OBS.app/Contents/Frameworks
  309. fi
  310. }
  311. install_frameworks() {
  312. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  313. if [ ! -d ./OBS.app ]; then
  314. error "No OBS.app bundle found"
  315. exit 1
  316. fi
  317. hr "Adding Chromium Embedded Framework"
  318. step "Copy Framework..."
  319. /bin/cp -R "${DEPS_BUILD_DIR}/cef_binary_${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}_macosx64/Release/Chromium Embedded Framework.framework" ./OBS.app/Contents/Frameworks/
  320. }
  321. prepare_macos_bundle() {
  322. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  323. if [ ! -d ./rundir/${BUILD_CONFIG}/bin ]; then
  324. error "No OBS build found"
  325. return
  326. fi
  327. if [ -d ./OBS.app ]; then /bin/rm -rf ./OBS.app; fi
  328. hr "Preparing OBS.app bundle"
  329. step "Copy binary and plugins..."
  330. /bin/mkdir -p OBS.app/Contents/MacOS
  331. /bin/mkdir OBS.app/Contents/PlugIns
  332. /bin/mkdir OBS.app/Contents/Resources
  333. /bin/mkdir OBS.app/Contents/Frameworks
  334. /bin/cp rundir/${BUILD_CONFIG}/bin/obs ./OBS.app/Contents/MacOS
  335. /bin/cp rundir/${BUILD_CONFIG}/bin/obs-ffmpeg-mux ./OBS.app/Contents/MacOS
  336. /bin/cp rundir/${BUILD_CONFIG}/bin/libobsglad.0.dylib ./OBS.app/Contents/MacOS
  337. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  338. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper.app" "./OBS.app/Contents/Frameworks/OBS Helper.app"
  339. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper (GPU).app" "./OBS.app/Contents/Frameworks/OBS Helper (GPU).app"
  340. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper (Plugin).app" "./OBS.app/Contents/Frameworks/OBS Helper (Plugin).app"
  341. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper (Renderer).app" "./OBS.app/Contents/Frameworks/OBS Helper (Renderer).app"
  342. fi
  343. /bin/cp -R rundir/${BUILD_CONFIG}/data ./OBS.app/Contents/Resources
  344. /bin/cp "${CI_SCRIPTS}/app/AppIcon.icns" ./OBS.app/Contents/Resources
  345. /bin/cp -R rundir/${BUILD_CONFIG}/obs-plugins/ ./OBS.app/Contents/PlugIns
  346. /bin/cp "${CI_SCRIPTS}/app/Info.plist" ./OBS.app/Contents
  347. # Scripting plugins are required to be placed in same directory as binary
  348. if [ -d ./OBS.app/Contents/Resources/data/obs-scripting ]; then
  349. /bin/mv ./OBS.app/Contents/Resources/data/obs-scripting/obslua.so ./OBS.app/Contents/MacOS/
  350. /bin/mv ./OBS.app/Contents/Resources/data/obs-scripting/_obspython.so ./OBS.app/Contents/MacOS/
  351. /bin/mv ./OBS.app/Contents/Resources/data/obs-scripting/obspython.py ./OBS.app/Contents/MacOS/
  352. /bin/rm -rf ./OBS.app/Contents/Resources/data/obs-scripting/
  353. fi
  354. bundle_dylibs
  355. install_frameworks
  356. /bin/cp "${CI_SCRIPTS}/app/OBSPublicDSAKey.pem" ./OBS.app/Contents/Resources
  357. step "Set bundle meta information..."
  358. /usr/bin/plutil -insert CFBundleVersion -string ${GIT_TAG}-${GIT_HASH} ./OBS.app/Contents/Info.plist
  359. /usr/bin/plutil -insert CFBundleShortVersionString -string ${GIT_TAG}-${GIT_HASH} ./OBS.app/Contents/Info.plist
  360. /usr/bin/plutil -insert OBSFeedsURL -string https://obsproject.com/osx_update/feeds.xml ./OBS.app/Contents/Info.plist
  361. /usr/bin/plutil -insert SUFeedURL -string https://obsproject.com/osx_update/stable/updates.xml ./OBS.app/Contents/Info.plist
  362. /usr/bin/plutil -insert SUPublicDSAKeyFile -string OBSPublicDSAKey.pem ./OBS.app/Contents/Info.plist
  363. }
  364. ## CREATE MACOS DISTRIBUTION AND INSTALLER IMAGE ##
  365. prepare_macos_image() {
  366. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  367. if [ ! -d ./OBS.app ]; then
  368. error "No OBS.app bundle found"
  369. return
  370. fi
  371. hr "Preparing macOS installation image"
  372. if [ -f "${FILE_NAME}" ]; then
  373. /bin/rm "${FILE_NAME}"
  374. fi
  375. step "Run dmgbuild..."
  376. /bin/cp "${CI_SCRIPTS}/package/settings.json.template" ./settings.json
  377. /usr/bin/sed -i '' 's#\$\$VERSION\$\$#'"${GIT_TAG}"'#g' ./settings.json
  378. /usr/bin/sed -i '' 's#\$\$CI_PATH\$\$#'"${CI_SCRIPTS}"'#g' ./settings.json
  379. /usr/bin/sed -i '' 's#\$\$BUNDLE_PATH\$\$#'"${CHECKOUT_DIR}"'/build#g' ./settings.json
  380. /bin/echo -n "${COLOR_ORANGE}"
  381. dmgbuild "OBS-Studio ${GIT_TAG}" "${FILE_NAME}" -s ./settings.json
  382. /bin/echo -n "${COLOR_RESET}"
  383. if [ -n "${CODESIGN_OBS}" ]; then
  384. codesign_image
  385. fi
  386. }
  387. ## SET UP CODE SIGNING AND NOTARIZATION CREDENTIALS ##
  388. ##############################################################################
  389. # Apple Developer Identity needed:
  390. #
  391. # + Signing the code requires a developer identity in the system's keychain
  392. # + codesign will look up and find the identity automatically
  393. #
  394. ##############################################################################
  395. read_codesign_ident() {
  396. if [ ! -n "${CODESIGN_IDENT}" ]; then
  397. step "Code-signing Setup"
  398. /usr/bin/read -p "${COLOR_ORANGE} + Apple developer identity: ${COLOR_RESET}" CODESIGN_IDENT
  399. fi
  400. }
  401. ##############################################################################
  402. # Apple Developer credentials necessary:
  403. #
  404. # + Signing for distribution and notarization require an active Apple
  405. # Developer membership
  406. # + An Apple Development identity is needed for code signing
  407. # (i.e. 'Apple Development: YOUR APPLE ID (PROVIDER)')
  408. # + Your Apple developer ID is needed for notarization
  409. # + An app-specific password is necessary for notarization from CLI
  410. # + This password will be stored in your macOS keychain under the identifier
  411. # 'OBS-Codesign-Password'with access Apple's 'altool' only.
  412. ##############################################################################
  413. read_codesign_pass() {
  414. if [ ! -n "${CODESIGN_IDENT_PASS}" ]; then
  415. step "Notarization Setup"
  416. /usr/bin/read -p "${COLOR_ORANGE} + Apple account id: ${COLOR_RESET}" CODESIGN_IDENT_USER
  417. CODESIGN_IDENT_PASS=$(stty -echo; /usr/bin/read -p "${COLOR_ORANGE} + Apple developer password: ${COLOR_RESET}" pwd; stty echo; /bin/echo $pwd)
  418. /bin/echo -n "${COLOR_ORANGE}"
  419. /usr/bin/xcrun altool --store-password-in-keychain-item "OBS-Codesign-Password" -u "${CODESIGN_IDENT_USER}" -p "${CODESIGN_IDENT_PASS}"
  420. /bin/echo -n "${COLOR_RESET}"
  421. CODESIGN_IDENT_SHORT=$(/bin/echo "${CODESIGN_IDENT}" | /usr/bin/sed -En "s/.+\((.+)\)/\1/p")
  422. fi
  423. }
  424. codesign_bundle() {
  425. if [ ! -n "${CODESIGN_OBS}" ]; then step "Skipping application bundle code signing"; return; fi
  426. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  427. trap "caught_error 'code-signing app'" ERR
  428. if [ ! -d ./OBS.app ]; then
  429. error "No OBS.app bundle found"
  430. return
  431. fi
  432. hr "Code-signing application bundle"
  433. /usr/bin/xattr -crs ./OBS.app
  434. read_codesign_ident
  435. step "Code-sign Sparkle framework..."
  436. /bin/echo -n "${COLOR_ORANGE}"
  437. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app/Contents/MacOS/fileop"
  438. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app/Contents/MacOS/Autoupdate"
  439. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" --deep ./OBS.app/Contents/Frameworks/Sparkle.framework
  440. /bin/echo -n "${COLOR_RESET}"
  441. step "Code-sign CEF framework..."
  442. /bin/echo -n "${COLOR_ORANGE}"
  443. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/app/entitlements.plist" --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libEGL.dylib"
  444. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/app/entitlements.plist" --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libswiftshader_libEGL.dylib"
  445. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/app/entitlements.plist" --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libGLESv2.dylib"
  446. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/app/entitlements.plist" --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libswiftshader_libGLESv2.dylib"
  447. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  448. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/app/entitlements.plist" --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libvk_swiftshader.dylib"
  449. fi
  450. /bin/echo -n "${COLOR_RESET}"
  451. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  452. step "Code-sign CEF helper apps..."
  453. /bin/echo -n "${COLOR_ORANGE}"
  454. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/helpers/helper-entitlements.plist" --sign "${CODESIGN_IDENT}" --deep "./OBS.app/Contents/Frameworks/OBS Helper.app"
  455. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/helpers/helper-gpu-entitlements.plist" --sign "${CODESIGN_IDENT}" --deep "./OBS.app/Contents/Frameworks/OBS Helper (GPU).app"
  456. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/helpers/helper-plugin-entitlements.plist" --sign "${CODESIGN_IDENT}" --deep "./OBS.app/Contents/Frameworks/OBS Helper (Plugin).app"
  457. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/helpers/helper-renderer-entitlements.plist" --sign "${CODESIGN_IDENT}" --deep "./OBS.app/Contents/Frameworks/OBS Helper (Renderer).app"
  458. /bin/echo -n "${COLOR_RESET}"
  459. fi
  460. step "Code-sign DAL Plugin..."
  461. /bin/echo -n "${COLOR_ORANGE}"
  462. /usr/bin/codesign --force --options runtime --deep --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Resources/data/obs-plugins/mac-virtualcam/obs-mac-virtualcam.plugin"
  463. /bin/echo -n "${COLOR_RESET}"
  464. step "Code-sign OBS code..."
  465. /bin/echo -n "${COLOR_ORANGE}"
  466. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/app/entitlements.plist" --sign "${CODESIGN_IDENT}" --deep ./OBS.app
  467. /bin/echo -n "${COLOR_RESET}"
  468. step "Check code-sign result..."
  469. /usr/bin/codesign -dvv ./OBS.app
  470. }
  471. codesign_image() {
  472. if [ ! -n "${CODESIGN_OBS}" ]; then step "Skipping installer image code signing"; return; fi
  473. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  474. trap "caught_error 'code-signing image'" ERR
  475. if [ ! -f "${FILE_NAME}" ]; then
  476. error "No OBS disk image found"
  477. return
  478. fi
  479. hr "Code-signing installation image"
  480. read_codesign_ident
  481. step "Code-sign OBS installer image..."
  482. /bin/echo -n "${COLOR_ORANGE}";
  483. /usr/bin/codesign --force --sign "${CODESIGN_IDENT}" "${FILE_NAME}"
  484. /bin/echo -n "${COLOR_RESET}"
  485. step "Check code-sign result..."
  486. /usr/bin/codesign -dvv "${FILE_NAME}"
  487. }
  488. ## BUILD FROM SOURCE META FUNCTION ##
  489. full-build-macos() {
  490. if [ -n "${SKIP_BUILD}" ]; then step "Skipping full build"; return; fi
  491. if [ ! -n "${SKIP_DEPS}" ]; then
  492. hr "Installing Homebrew dependencies"
  493. install_homebrew_deps
  494. for DEPENDENCY in "${BUILD_DEPS[@]}"; do
  495. set -- ${DEPENDENCY}
  496. trap "caught_error ${DEPENDENCY}" ERR
  497. FUNC_NAME="install_${1}"
  498. ${FUNC_NAME} ${2} ${3}
  499. done
  500. check_ccache
  501. trap "caught_error 'cmake'" ERR
  502. fi
  503. configure_obs_build
  504. run_obs_build
  505. }
  506. ## BUNDLE MACOS APPLICATION META FUNCTION ##
  507. bundle_macos() {
  508. if [ ! -n "${BUNDLE_OBS}" ]; then step "Skipping application bundle creation"; return; fi
  509. hr "Creating macOS app bundle"
  510. trap "caught_error 'bundle app'" ERR
  511. ensure_dir ${CHECKOUT_DIR}
  512. prepare_macos_bundle
  513. }
  514. ## PACKAGE MACOS DISTRIBUTION IMAGE META FUNCTION ##
  515. package_macos() {
  516. if [ ! -n "${PACKAGE_OBS}" ]; then step "Skipping installer image creation"; return; fi
  517. hr "Creating macOS .dmg image"
  518. trap "caught_error 'package app'" ERR
  519. install_dmgbuild
  520. prepare_macos_image
  521. }
  522. ## NOTARIZATION META FUNCTION ##
  523. notarize_macos() {
  524. if [ ! -n "${NOTARIZE_OBS}" ]; then step "Skipping macOS notarization"; return; fi;
  525. hr "Notarizing OBS for macOS"
  526. trap "caught_error 'notarizing app'" ERR
  527. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  528. if [ -f "${FILE_NAME}" ]; then
  529. NOTARIZE_TARGET="${FILE_NAME}"
  530. xcnotary precheck "./OBS.app"
  531. elif [ -d "OBS.app" ]; then
  532. NOTARIZE_TARGET="./OBS.app"
  533. else
  534. error "No notarization app bundle ('OBS.app') or disk image ('${FILE_NAME}') found"
  535. return
  536. fi
  537. if [ "$?" -eq 0 ]; then
  538. read_codesign_ident
  539. read_codesign_pass
  540. step "Run xcnotary with ${NOTARIZE_TARGET}..."
  541. xcnotary notarize "${NOTARIZE_TARGET}" --developer-account "${CODESIGN_IDENT_USER}" --developer-password-keychain-item "OBS-Codesign-Password" --provider "${CODESIGN_IDENT_SHORT}"
  542. fi
  543. }
  544. ## MAIN SCRIPT FUNCTIONS ##
  545. print_usage() {
  546. /bin/echo "full-build-macos.sh - Build helper script for OBS-Studio\n"
  547. /bin/echo "Usage: ${0}\n" \
  548. "-d: Skip dependency checks\n" \
  549. "-b: Create macOS app bundle\n" \
  550. "-c: Codesign macOS app bundle\n" \
  551. "-p: Package macOS app into disk image\n" \
  552. "-n: Notarize macOS app and disk image (implies -b)\n" \
  553. "-s: Skip build process (useful for bundling/packaging only)\n" \
  554. "-h: Print this help"
  555. exit 0
  556. }
  557. obs-build-main() {
  558. ensure_dir ${CHECKOUT_DIR}
  559. check_macos_version
  560. step "Fetching OBS tags..."
  561. /usr/bin/git fetch origin --tags
  562. GIT_BRANCH=$(/usr/bin/git rev-parse --abbrev-ref HEAD)
  563. GIT_HASH=$(/usr/bin/git rev-parse --short HEAD)
  564. GIT_TAG=$(/usr/bin/git describe --tags --abbrev=0)
  565. FILE_NAME="obs-studio-${GIT_TAG}-${GIT_HASH}-macOS.dmg"
  566. ##########################################################################
  567. # IMPORTANT:
  568. #
  569. # Be careful when choosing to notarize and code-sign. The script will try
  570. # to sign any pre-existing bundle but also pre-existing images.
  571. #
  572. # This could lead to a package containing a non-signed bundle, which
  573. # will then fail notarization.
  574. #
  575. # To avoid this, run this script with -b -c first, then -p -c or -p -n
  576. # after to make sure that a code-signed bundle will be packaged.
  577. #
  578. ##########################################################################
  579. while getopts ":hdsbnpc" OPTION; do
  580. case ${OPTION} in
  581. h) print_usage ;;
  582. d) SKIP_DEPS=1 ;;
  583. s) SKIP_BUILD=1 ;;
  584. b) BUNDLE_OBS=1 ;;
  585. n) CODESIGN_OBS=1; NOTARIZE_OBS=1 ;;
  586. p) PACKAGE_OBS=1 ;;
  587. c) CODESIGN_OBS=1 ;;
  588. \?) ;;
  589. esac
  590. done
  591. full-build-macos
  592. bundle_macos
  593. codesign_bundle
  594. package_macos
  595. codesign_image
  596. notarize_macos
  597. cleanup
  598. }
  599. obs-build-main $*