full-build-macos.sh 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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. )
  288. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  289. "${CI_SCRIPTS}/app/dylibbundler" -cd -of -a ./OBS.app -q -f \
  290. -s ./OBS.app/Contents/MacOS \
  291. -s "${DEPS_BUILD_DIR}/sparkle/Sparkle.framework" \
  292. -s ./rundir/${BUILD_CONFIG}/bin/ \
  293. $(echo "${BUNDLE_PLUGINS[@]/#/-x }")
  294. else
  295. "${CI_SCRIPTS}/app/dylibbundler" -cd -of -a ./OBS.app -q -f \
  296. -s ./OBS.app/Contents/MacOS \
  297. -s "${DEPS_BUILD_DIR}/sparkle/Sparkle.framework" \
  298. -s ./rundir/${BUILD_CONFIG}/bin/ \
  299. $(echo "${BUNDLE_PLUGINS[@]/#/-x }") \
  300. -x ./OBS.app/Contents/PlugIns/obs-browser-page
  301. fi
  302. step "Move libobs-opengl to final destination"
  303. if [ -f "./libobs-opengl/libobs-opengl.so" ]; then
  304. /bin/cp ./libobs-opengl/libobs-opengl.so ./OBS.app/Contents/Frameworks
  305. else
  306. /bin/cp ./libobs-opengl/${BUILD_CONFIG}/libobs-opengl.so ./OBS.app/Contents/Frameworks
  307. fi
  308. step "Copy QtNetwork for plugin support"
  309. /bin/cp -R /tmp/obsdeps/lib/QtNetwork.framework ./OBS.app/Contents/Frameworks
  310. /bin/chmod -R +w ./OBS.app/Contents/Frameworks/QtNetwork.framework
  311. /bin/rm -r ./OBS.app/Contents/Frameworks/QtNetwork.framework/Headers
  312. /bin/rm -r ./OBS.app/Contents/Frameworks/QtNetwork.framework/Versions/5/Headers/
  313. /bin/chmod 644 ./OBS.app/Contents/Frameworks/QtNetwork.framework/Versions/5/Resources/Info.plist
  314. install_name_tool -id @executable_path/../Frameworks/QtNetwork.framework/Versions/5/QtNetwork ./OBS.app/Contents/Frameworks/QtNetwork.framework/Versions/5/QtNetwork
  315. install_name_tool -change /tmp/obsdeps/lib/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore ./OBS.app/Contents/Frameworks/QtNetwork.framework/Versions/5/QtNetwork
  316. }
  317. install_frameworks() {
  318. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  319. if [ ! -d ./OBS.app ]; then
  320. error "No OBS.app bundle found"
  321. exit 1
  322. fi
  323. hr "Adding Chromium Embedded Framework"
  324. step "Copy Framework..."
  325. /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/
  326. }
  327. prepare_macos_bundle() {
  328. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  329. if [ ! -d ./rundir/${BUILD_CONFIG}/bin ]; then
  330. error "No OBS build found"
  331. return
  332. fi
  333. if [ -d ./OBS.app ]; then /bin/rm -rf ./OBS.app; fi
  334. hr "Preparing OBS.app bundle"
  335. step "Copy binary and plugins..."
  336. /bin/mkdir -p OBS.app/Contents/MacOS
  337. /bin/mkdir OBS.app/Contents/PlugIns
  338. /bin/mkdir OBS.app/Contents/Resources
  339. /bin/mkdir OBS.app/Contents/Frameworks
  340. /bin/cp rundir/${BUILD_CONFIG}/bin/obs ./OBS.app/Contents/MacOS
  341. /bin/cp rundir/${BUILD_CONFIG}/bin/obs-ffmpeg-mux ./OBS.app/Contents/MacOS
  342. /bin/cp rundir/${BUILD_CONFIG}/bin/libobsglad.0.dylib ./OBS.app/Contents/MacOS
  343. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  344. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper.app" "./OBS.app/Contents/Frameworks/OBS Helper.app"
  345. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper (GPU).app" "./OBS.app/Contents/Frameworks/OBS Helper (GPU).app"
  346. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper (Plugin).app" "./OBS.app/Contents/Frameworks/OBS Helper (Plugin).app"
  347. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper (Renderer).app" "./OBS.app/Contents/Frameworks/OBS Helper (Renderer).app"
  348. fi
  349. /bin/cp -R rundir/${BUILD_CONFIG}/data ./OBS.app/Contents/Resources
  350. /bin/cp "${CI_SCRIPTS}/app/AppIcon.icns" ./OBS.app/Contents/Resources
  351. /bin/cp -R rundir/${BUILD_CONFIG}/obs-plugins/ ./OBS.app/Contents/PlugIns
  352. /bin/cp "${CI_SCRIPTS}/app/Info.plist" ./OBS.app/Contents
  353. # Scripting plugins are required to be placed in same directory as binary
  354. if [ -d ./OBS.app/Contents/Resources/data/obs-scripting ]; then
  355. /bin/mv ./OBS.app/Contents/Resources/data/obs-scripting/obslua.so ./OBS.app/Contents/MacOS/
  356. /bin/mv ./OBS.app/Contents/Resources/data/obs-scripting/_obspython.so ./OBS.app/Contents/MacOS/
  357. /bin/mv ./OBS.app/Contents/Resources/data/obs-scripting/obspython.py ./OBS.app/Contents/MacOS/
  358. /bin/rm -rf ./OBS.app/Contents/Resources/data/obs-scripting/
  359. fi
  360. bundle_dylibs
  361. install_frameworks
  362. /bin/cp "${CI_SCRIPTS}/app/OBSPublicDSAKey.pem" ./OBS.app/Contents/Resources
  363. step "Set bundle meta information..."
  364. /usr/bin/plutil -insert CFBundleVersion -string ${GIT_TAG}-${GIT_HASH} ./OBS.app/Contents/Info.plist
  365. /usr/bin/plutil -insert CFBundleShortVersionString -string ${GIT_TAG}-${GIT_HASH} ./OBS.app/Contents/Info.plist
  366. /usr/bin/plutil -insert OBSFeedsURL -string https://obsproject.com/osx_update/feeds.xml ./OBS.app/Contents/Info.plist
  367. /usr/bin/plutil -insert SUFeedURL -string https://obsproject.com/osx_update/stable/updates.xml ./OBS.app/Contents/Info.plist
  368. /usr/bin/plutil -insert SUPublicDSAKeyFile -string OBSPublicDSAKey.pem ./OBS.app/Contents/Info.plist
  369. }
  370. ## CREATE MACOS DISTRIBUTION AND INSTALLER IMAGE ##
  371. prepare_macos_image() {
  372. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  373. if [ ! -d ./OBS.app ]; then
  374. error "No OBS.app bundle found"
  375. return
  376. fi
  377. hr "Preparing macOS installation image"
  378. if [ -f "${FILE_NAME}" ]; then
  379. /bin/rm "${FILE_NAME}"
  380. fi
  381. step "Run dmgbuild..."
  382. /bin/cp "${CI_SCRIPTS}/package/settings.json.template" ./settings.json
  383. /usr/bin/sed -i '' 's#\$\$VERSION\$\$#'"${GIT_TAG}"'#g' ./settings.json
  384. /usr/bin/sed -i '' 's#\$\$CI_PATH\$\$#'"${CI_SCRIPTS}"'#g' ./settings.json
  385. /usr/bin/sed -i '' 's#\$\$BUNDLE_PATH\$\$#'"${CHECKOUT_DIR}"'/build#g' ./settings.json
  386. /bin/echo -n "${COLOR_ORANGE}"
  387. dmgbuild "OBS-Studio ${GIT_TAG}" "${FILE_NAME}" -s ./settings.json
  388. /bin/echo -n "${COLOR_RESET}"
  389. if [ -n "${CODESIGN_OBS}" ]; then
  390. codesign_image
  391. fi
  392. }
  393. ## SET UP CODE SIGNING AND NOTARIZATION CREDENTIALS ##
  394. ##############################################################################
  395. # Apple Developer Identity needed:
  396. #
  397. # + Signing the code requires a developer identity in the system's keychain
  398. # + codesign will look up and find the identity automatically
  399. #
  400. ##############################################################################
  401. read_codesign_ident() {
  402. if [ ! -n "${CODESIGN_IDENT}" ]; then
  403. step "Code-signing Setup"
  404. /usr/bin/read -p "${COLOR_ORANGE} + Apple developer identity: ${COLOR_RESET}" CODESIGN_IDENT
  405. fi
  406. }
  407. ##############################################################################
  408. # Apple Developer credentials necessary:
  409. #
  410. # + Signing for distribution and notarization require an active Apple
  411. # Developer membership
  412. # + An Apple Development identity is needed for code signing
  413. # (i.e. 'Apple Development: YOUR APPLE ID (PROVIDER)')
  414. # + Your Apple developer ID is needed for notarization
  415. # + An app-specific password is necessary for notarization from CLI
  416. # + This password will be stored in your macOS keychain under the identifier
  417. # 'OBS-Codesign-Password'with access Apple's 'altool' only.
  418. ##############################################################################
  419. read_codesign_pass() {
  420. if [ ! -n "${CODESIGN_IDENT_PASS}" ]; then
  421. step "Notarization Setup"
  422. /usr/bin/read -p "${COLOR_ORANGE} + Apple account id: ${COLOR_RESET}" CODESIGN_IDENT_USER
  423. CODESIGN_IDENT_PASS=$(stty -echo; /usr/bin/read -p "${COLOR_ORANGE} + Apple developer password: ${COLOR_RESET}" pwd; stty echo; /bin/echo $pwd)
  424. /bin/echo -n "${COLOR_ORANGE}"
  425. /usr/bin/xcrun altool --store-password-in-keychain-item "OBS-Codesign-Password" -u "${CODESIGN_IDENT_USER}" -p "${CODESIGN_IDENT_PASS}"
  426. /bin/echo -n "${COLOR_RESET}"
  427. CODESIGN_IDENT_SHORT=$(/bin/echo "${CODESIGN_IDENT}" | /usr/bin/sed -En "s/.+\((.+)\)/\1/p")
  428. fi
  429. }
  430. codesign_bundle() {
  431. if [ ! -n "${CODESIGN_OBS}" ]; then step "Skipping application bundle code signing"; return; fi
  432. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  433. trap "caught_error 'code-signing app'" ERR
  434. if [ ! -d ./OBS.app ]; then
  435. error "No OBS.app bundle found"
  436. return
  437. fi
  438. hr "Code-signing application bundle"
  439. /usr/bin/xattr -crs ./OBS.app
  440. read_codesign_ident
  441. step "Code-sign Sparkle framework..."
  442. /bin/echo -n "${COLOR_ORANGE}"
  443. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app/Contents/MacOS/fileop"
  444. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app/Contents/MacOS/Autoupdate"
  445. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" --deep ./OBS.app/Contents/Frameworks/Sparkle.framework
  446. /bin/echo -n "${COLOR_RESET}"
  447. step "Code-sign CEF framework..."
  448. /bin/echo -n "${COLOR_ORANGE}"
  449. /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"
  450. /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"
  451. /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"
  452. /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"
  453. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  454. /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"
  455. fi
  456. /bin/echo -n "${COLOR_RESET}"
  457. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  458. step "Code-sign CEF helper apps..."
  459. /bin/echo -n "${COLOR_ORANGE}"
  460. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/helpers/helper-entitlements.plist" --sign "${CODESIGN_IDENT}" --deep "./OBS.app/Contents/Frameworks/OBS Helper.app"
  461. /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"
  462. /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"
  463. /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"
  464. /bin/echo -n "${COLOR_RESET}"
  465. fi
  466. step "Code-sign DAL Plugin..."
  467. /bin/echo -n "${COLOR_ORANGE}"
  468. /usr/bin/codesign --force --options runtime --deep --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Resources/data/obs-mac-virtualcam.plugin"
  469. /bin/echo -n "${COLOR_RESET}"
  470. step "Code-sign OBS code..."
  471. /bin/echo -n "${COLOR_ORANGE}"
  472. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/app/entitlements.plist" --sign "${CODESIGN_IDENT}" --deep ./OBS.app
  473. /bin/echo -n "${COLOR_RESET}"
  474. step "Check code-sign result..."
  475. /usr/bin/codesign -dvv ./OBS.app
  476. }
  477. codesign_image() {
  478. if [ ! -n "${CODESIGN_OBS}" ]; then step "Skipping installer image code signing"; return; fi
  479. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  480. trap "caught_error 'code-signing image'" ERR
  481. if [ ! -f "${FILE_NAME}" ]; then
  482. error "No OBS disk image found"
  483. return
  484. fi
  485. hr "Code-signing installation image"
  486. read_codesign_ident
  487. step "Code-sign OBS installer image..."
  488. /bin/echo -n "${COLOR_ORANGE}";
  489. /usr/bin/codesign --force --sign "${CODESIGN_IDENT}" "${FILE_NAME}"
  490. /bin/echo -n "${COLOR_RESET}"
  491. step "Check code-sign result..."
  492. /usr/bin/codesign -dvv "${FILE_NAME}"
  493. }
  494. ## BUILD FROM SOURCE META FUNCTION ##
  495. full-build-macos() {
  496. if [ -n "${SKIP_BUILD}" ]; then step "Skipping full build"; return; fi
  497. if [ ! -n "${SKIP_DEPS}" ]; then
  498. hr "Installing Homebrew dependencies"
  499. install_homebrew_deps
  500. for DEPENDENCY in "${BUILD_DEPS[@]}"; do
  501. set -- ${DEPENDENCY}
  502. trap "caught_error ${DEPENDENCY}" ERR
  503. FUNC_NAME="install_${1}"
  504. ${FUNC_NAME} ${2} ${3}
  505. done
  506. check_ccache
  507. trap "caught_error 'cmake'" ERR
  508. fi
  509. configure_obs_build
  510. run_obs_build
  511. }
  512. ## BUNDLE MACOS APPLICATION META FUNCTION ##
  513. bundle_macos() {
  514. if [ ! -n "${BUNDLE_OBS}" ]; then step "Skipping application bundle creation"; return; fi
  515. hr "Creating macOS app bundle"
  516. trap "caught_error 'bundle app'" ERR
  517. ensure_dir ${CHECKOUT_DIR}
  518. prepare_macos_bundle
  519. }
  520. ## PACKAGE MACOS DISTRIBUTION IMAGE META FUNCTION ##
  521. package_macos() {
  522. if [ ! -n "${PACKAGE_OBS}" ]; then step "Skipping installer image creation"; return; fi
  523. hr "Creating macOS .dmg image"
  524. trap "caught_error 'package app'" ERR
  525. install_dmgbuild
  526. prepare_macos_image
  527. }
  528. ## NOTARIZATION META FUNCTION ##
  529. notarize_macos() {
  530. if [ ! -n "${NOTARIZE_OBS}" ]; then step "Skipping macOS notarization"; return; fi;
  531. hr "Notarizing OBS for macOS"
  532. trap "caught_error 'notarizing app'" ERR
  533. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  534. if [ -f "${FILE_NAME}" ]; then
  535. NOTARIZE_TARGET="${FILE_NAME}"
  536. xcnotary precheck "./OBS.app"
  537. elif [ -d "OBS.app" ]; then
  538. NOTARIZE_TARGET="./OBS.app"
  539. else
  540. error "No notarization app bundle ('OBS.app') or disk image ('${FILE_NAME}') found"
  541. return
  542. fi
  543. if [ "$?" -eq 0 ]; then
  544. read_codesign_ident
  545. read_codesign_pass
  546. step "Run xcnotary with ${NOTARIZE_TARGET}..."
  547. xcnotary notarize "${NOTARIZE_TARGET}" --developer-account "${CODESIGN_IDENT_USER}" --developer-password-keychain-item "OBS-Codesign-Password" --provider "${CODESIGN_IDENT_SHORT}"
  548. fi
  549. }
  550. ## MAIN SCRIPT FUNCTIONS ##
  551. print_usage() {
  552. /bin/echo "full-build-macos.sh - Build helper script for OBS-Studio\n"
  553. /bin/echo "Usage: ${0}\n" \
  554. "-d: Skip dependency checks\n" \
  555. "-b: Create macOS app bundle\n" \
  556. "-c: Codesign macOS app bundle\n" \
  557. "-p: Package macOS app into disk image\n" \
  558. "-n: Notarize macOS app and disk image (implies -b)\n" \
  559. "-s: Skip build process (useful for bundling/packaging only)\n" \
  560. "-h: Print this help"
  561. exit 0
  562. }
  563. obs-build-main() {
  564. ensure_dir ${CHECKOUT_DIR}
  565. check_macos_version
  566. step "Fetching OBS tags..."
  567. /usr/bin/git fetch origin --tags
  568. GIT_BRANCH=$(/usr/bin/git rev-parse --abbrev-ref HEAD)
  569. GIT_HASH=$(/usr/bin/git rev-parse --short HEAD)
  570. GIT_TAG=$(/usr/bin/git describe --tags --abbrev=0)
  571. FILE_NAME="obs-studio-${GIT_TAG}-${GIT_HASH}-macOS.dmg"
  572. ##########################################################################
  573. # IMPORTANT:
  574. #
  575. # Be careful when choosing to notarize and code-sign. The script will try
  576. # to sign any pre-existing bundle but also pre-existing images.
  577. #
  578. # This could lead to a package containing a non-signed bundle, which
  579. # will then fail notarization.
  580. #
  581. # To avoid this, run this script with -b -c first, then -p -c or -p -n
  582. # after to make sure that a code-signed bundle will be packaged.
  583. #
  584. ##########################################################################
  585. while getopts ":hdsbnpc" OPTION; do
  586. case ${OPTION} in
  587. h) print_usage ;;
  588. d) SKIP_DEPS=1 ;;
  589. s) SKIP_BUILD=1 ;;
  590. b) BUNDLE_OBS=1 ;;
  591. n) CODESIGN_OBS=1; NOTARIZE_OBS=1 ;;
  592. p) PACKAGE_OBS=1 ;;
  593. c) CODESIGN_OBS=1 ;;
  594. \?) ;;
  595. esac
  596. done
  597. full-build-macos
  598. bundle_macos
  599. codesign_bundle
  600. package_macos
  601. codesign_image
  602. notarize_macos
  603. cleanup
  604. }
  605. obs-build-main $*