full-build-macos.sh 27 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. BUILD_DEPS=(
  48. "obs-deps ${MACOS_DEPS_VERSION:-${CI_DEPS_VERSION}}"
  49. "qt-deps ${QT_VERSION:-${CI_QT_VERSION}} ${MACOS_DEPS_VERSION:-${CI_DEPS_VERSION}}"
  50. "cef ${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}"
  51. "vlc ${VLC_VERSION:-${CI_VLC_VERSION}}"
  52. "sparkle ${SPARKLE_VERSION:-${CI_SPARKLE_VERSION}}"
  53. )
  54. if [ -n "${TERM-}" ]; then
  55. COLOR_RED=$(/usr/bin/tput setaf 1)
  56. COLOR_GREEN=$(/usr/bin/tput setaf 2)
  57. COLOR_BLUE=$(/usr/bin/tput setaf 4)
  58. COLOR_ORANGE=$(/usr/bin/tput setaf 3)
  59. COLOR_RESET=$(/usr/bin/tput sgr0)
  60. else
  61. COLOR_RED=""
  62. COLOR_GREEN=""
  63. COLOR_BLUE=""
  64. COLOR_ORANGE=""
  65. COLOR_RESET=""
  66. fi
  67. MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)"
  68. MACOS_MAJOR="$(/bin/echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 1)"
  69. MACOS_MINOR="$(/bin/echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 2)"
  70. ## DEFINE UTILITIES ##
  71. hr() {
  72. /bin/echo "${COLOR_BLUE}[${PRODUCT_NAME}] ${1}${COLOR_RESET}"
  73. }
  74. step() {
  75. /bin/echo "${COLOR_GREEN} + ${1}${COLOR_RESET}"
  76. }
  77. info() {
  78. /bin/echo "${COLOR_ORANGE} + ${1}${COLOR_RESET}"
  79. }
  80. error() {
  81. /bin/echo "${COLOR_RED} + ${1}${COLOR_RESET}"
  82. }
  83. exists() {
  84. /usr/bin/command -v "$1" >/dev/null 2>&1
  85. }
  86. ensure_dir() {
  87. [[ -n ${1} ]] && /bin/mkdir -p ${1} && builtin cd ${1}
  88. }
  89. cleanup() {
  90. /bin/rm -rf "${CHECKOUT_DIR}/${BUILD_DIR}/settings.json"
  91. unset CODESIGN_IDENT
  92. unset CODESIGN_IDENT_USER
  93. unset CODESIGN_IDENT_PASS
  94. }
  95. caught_error() {
  96. error "ERROR during build step: ${1}"
  97. cleanup
  98. exit 1
  99. }
  100. ## CHECK AND INSTALL DEPENDENCIES ##
  101. check_macos_version() {
  102. MIN_VERSION=${MIN_MACOS_VERSION:-${CI_MIN_MACOS_VERSION}}
  103. MIN_MAJOR=$(/bin/echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 1)
  104. MIN_MINOR=$(/bin/echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 2)
  105. if [ "${MACOS_MAJOR}" -lt "11" ] && [ "${MACOS_MINOR}" -lt "${MIN_MINOR}" ]; then
  106. error "WARNING: Minimum required macOS version is ${MIN_VERSION}, but running on ${MACOS_VERSION}"
  107. fi
  108. }
  109. install_homebrew_deps() {
  110. if ! exists brew; then
  111. error "Homebrew not found - please install homebrew (https://brew.sh)"
  112. exit 1
  113. fi
  114. if [ -d /usr/local/opt/[email protected] ]; then
  115. brew uninstall [email protected]
  116. brew untap local/openssl
  117. fi
  118. if [ -d /usr/local/opt/[email protected] ]; then
  119. brew uninstall [email protected]
  120. brew untap local/python2
  121. fi
  122. brew bundle --file ${CI_SCRIPTS}/Brewfile
  123. check_curl
  124. }
  125. check_curl() {
  126. if [ "${MACOS_MAJOR}" -lt "11" ] && [ "${MACOS_MINOR}" -lt "15" ]; then
  127. if [ ! -d /usr/local/opt/curl ]; then
  128. step "Installing Homebrew curl.."
  129. brew install curl
  130. fi
  131. export CURLCMD="/usr/local/opt/curl/bin/curl"
  132. else
  133. export CURLCMD="curl"
  134. fi
  135. }
  136. check_ccache() {
  137. export PATH=/usr/local/opt/ccache/libexec:${PATH}
  138. CCACHE_STATUS=$(ccache -s >/dev/null 2>&1 && /bin/echo "CCache available." || /bin/echo "CCache is not available.")
  139. info "${CCACHE_STATUS}"
  140. }
  141. install_obs-deps() {
  142. hr "Setting up pre-built macOS OBS dependencies v${1}"
  143. ensure_dir ${DEPS_BUILD_DIR}
  144. step "Download..."
  145. ${CURLCMD} --progress-bar -L -C - -O https://github.com/obsproject/obs-deps/releases/download/${1}/macos-deps-${1}.tar.gz
  146. step "Unpack..."
  147. /usr/bin/tar -xf ./macos-deps-${1}.tar.gz -C /tmp
  148. }
  149. install_qt-deps() {
  150. hr "Setting up pre-built dependency QT v${1}"
  151. ensure_dir ${DEPS_BUILD_DIR}
  152. step "Download..."
  153. ${CURLCMD} --progress-bar -L -C - -O https://github.com/obsproject/obs-deps/releases/download/${2}/macos-qt-${1}-${2}.tar.gz
  154. step "Unpack..."
  155. /usr/bin/tar -xf ./macos-qt-${1}-${2}.tar.gz -C /tmp
  156. /usr/bin/xattr -r -d com.apple.quarantine /tmp/obsdeps
  157. }
  158. install_vlc() {
  159. hr "Setting up dependency VLC v${1}"
  160. ensure_dir ${DEPS_BUILD_DIR}
  161. step "Download..."
  162. ${CURLCMD} --progress-bar -L -C - -O https://downloads.videolan.org/vlc/${1}/vlc-${1}.tar.xz
  163. step "Unpack ..."
  164. /usr/bin/tar -xf vlc-${1}.tar.xz
  165. }
  166. install_sparkle() {
  167. hr "Setting up dependency Sparkle v${1} (might prompt for password)"
  168. ensure_dir ${DEPS_BUILD_DIR}/sparkle
  169. step "Download..."
  170. ${CURLCMD} --progress-bar -L -C - -o sparkle.tar.bz2 https://github.com/sparkle-project/Sparkle/releases/download/${1}/Sparkle-${1}.tar.bz2
  171. step "Unpack..."
  172. /usr/bin/tar -xf ./sparkle.tar.bz2
  173. step "Copy to destination..."
  174. if [ -d /Library/Frameworks/Sparkle.framework/ ]; then
  175. info "Warning - Sparkle framework already found in /Library/Frameworks"
  176. else
  177. sudo /bin/cp -R ./Sparkle.framework/ /Library/Frameworks/Sparkle.framework/
  178. fi
  179. }
  180. install_cef() {
  181. hr "Building dependency CEF v${1}"
  182. ensure_dir ${DEPS_BUILD_DIR}
  183. step "Download..."
  184. ${CURLCMD} --progress-bar -L -C - -O https://cdn-fastly.obsproject.com/downloads/cef_binary_${1}_macosx64.tar.bz2
  185. step "Unpack..."
  186. /usr/bin/tar -xf ./cef_binary_${1}_macosx64.tar.bz2
  187. cd ./cef_binary_${1}_macosx64
  188. step "Fix tests..."
  189. /usr/bin/sed -i '.orig' '/add_subdirectory(tests\/ceftests)/d' ./CMakeLists.txt
  190. /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
  191. ensure_dir ./build
  192. step "Run CMAKE..."
  193. cmake \
  194. -DCMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++ -Wno-deprecated-declarations"\
  195. -DCMAKE_EXE_LINKER_FLAGS="-std=c++11 -stdlib=libc++"\
  196. -DCMAKE_OSX_DEPLOYMENT_TARGET=${MIN_MACOS_VERSION:-${CI_MIN_MACOS_VERSION}} \
  197. ..
  198. step "Build..."
  199. /usr/bin/make -j${NPROC}
  200. if [ ! -d libcef_dll ]; then /bin/mkdir libcef_dll; fi
  201. }
  202. ## CHECK AND INSTALL PACKAGING DEPENDENCIES ##
  203. install_dmgbuild() {
  204. if ! exists dmgbuild; then
  205. if exists "pip3"; then
  206. PIPCMD="pip3"
  207. elif exists "pip"; then
  208. PIPCMD="pip"
  209. else
  210. error "Pip not found - please install pip via 'python -m ensurepip'"
  211. exit 1
  212. fi
  213. ${PIPCMD} install dmgbuild
  214. fi
  215. }
  216. ## OBS BUILD FROM SOURCE ##
  217. configure_obs_build() {
  218. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  219. CUR_DATE=$(/bin/date +"%Y-%m-%d@%H%M%S")
  220. NIGHTLY_DIR="${CHECKOUT_DIR}/nightly-${CUR_DATE}"
  221. PACKAGE_NAME=$(/usr/bin/find . -name "*.dmg")
  222. if [ -d ./OBS.app ]; then
  223. ensure_dir "${NIGHTLY_DIR}"
  224. /bin/mv ../${BUILD_DIR}/OBS.app .
  225. info "You can find OBS.app in ${NIGHTLY_DIR}"
  226. fi
  227. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  228. if ([ -n "${PACKAGE_NAME}" ] && [ -f ${PACKAGE_NAME} ]); then
  229. ensure_dir "${NIGHTLY_DIR}"
  230. /bin/mv ../${BUILD_DIR}/$(basename "${PACKAGE_NAME}") .
  231. info "You can find ${PACKAGE_NAME} in ${NIGHTLY_DIR}"
  232. fi
  233. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  234. hr "Run CMAKE for OBS..."
  235. cmake -DENABLE_SPARKLE_UPDATER=ON \
  236. -DCMAKE_OSX_DEPLOYMENT_TARGET=${MIN_MACOS_VERSION:-${CI_MIN_MACOS_VERSION}} \
  237. -DQTDIR="/tmp/obsdeps" \
  238. -DSWIGDIR="/tmp/obsdeps" \
  239. -DDepsPath="/tmp/obsdeps" \
  240. -DVLCPath="${DEPS_BUILD_DIR}/vlc-${VLC_VERSION:-${CI_VLC_VERSION}}" \
  241. -DBUILD_BROWSER=ON \
  242. -DBROWSER_LEGACY="$(test "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 && echo "ON" || echo "OFF")" \
  243. -DWITH_RTMPS=ON \
  244. -DCEF_ROOT_DIR="${DEPS_BUILD_DIR}/cef_binary_${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}_macosx64" \
  245. -DCMAKE_BUILD_TYPE="${BUILD_CONFIG}" \
  246. ..
  247. }
  248. run_obs_build() {
  249. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  250. hr "Build OBS..."
  251. /usr/bin/make -j${NPROC}
  252. }
  253. ## OBS BUNDLE AS MACOS APPLICATION ##
  254. bundle_dylibs() {
  255. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  256. if [ ! -d ./OBS.app ]; then
  257. error "No OBS.app bundle found"
  258. exit 1
  259. fi
  260. hr "Bundle dylibs for macOS application"
  261. step "Run dylibBundler.."
  262. BUNDLE_PLUGINS=(
  263. ./OBS.app/Contents/PlugIns/coreaudio-encoder.so
  264. ./OBS.app/Contents/PlugIns/decklink-ouput-ui.so
  265. ./OBS.app/Contents/PlugIns/decklink-captions.so
  266. ./OBS.app/Contents/PlugIns/frontend-tools.so
  267. ./OBS.app/Contents/PlugIns/image-source.so
  268. ./OBS.app/Contents/PlugIns/mac-avcapture.so
  269. ./OBS.app/Contents/PlugIns/mac-capture.so
  270. ./OBS.app/Contents/PlugIns/mac-decklink.so
  271. ./OBS.app/Contents/PlugIns/mac-syphon.so
  272. ./OBS.app/Contents/PlugIns/mac-vth264.so
  273. ./OBS.app/Contents/PlugIns/mac-virtualcam.so
  274. ./OBS.app/Contents/PlugIns/obs-browser.so
  275. ./OBS.app/Contents/PlugIns/obs-ffmpeg.so
  276. ./OBS.app/Contents/PlugIns/obs-filters.so
  277. ./OBS.app/Contents/PlugIns/obs-transitions.so
  278. ./OBS.app/Contents/PlugIns/obs-vst.so
  279. ./OBS.app/Contents/PlugIns/rtmp-services.so
  280. ./OBS.app/Contents/MacOS/obs-ffmpeg-mux
  281. ./OBS.app/Contents/MacOS/obslua.so
  282. ./OBS.app/Contents/MacOS/_obspython.so
  283. ./OBS.app/Contents/PlugIns/obs-x264.so
  284. ./OBS.app/Contents/PlugIns/text-freetype2.so
  285. ./OBS.app/Contents/PlugIns/obs-outputs.so
  286. )
  287. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  288. ${CI_SCRIPTS}/app/dylibbundler -cd -of -a ./OBS.app -q -f \
  289. -s ./OBS.app/Contents/MacOS \
  290. -s "${DEPS_BUILD_DIR}/sparkle/Sparkle.framework" \
  291. -s ./rundir/${BUILD_CONFIG}/bin/ \
  292. $(echo "${BUNDLE_PLUGINS[@]/#/-x }")
  293. else
  294. ${CI_SCRIPTS}/app/dylibbundler -cd -of -a ./OBS.app -q -f \
  295. -s ./OBS.app/Contents/MacOS \
  296. -s "${DEPS_BUILD_DIR}/sparkle/Sparkle.framework" \
  297. -s ./rundir/${BUILD_CONFIG}/bin/ \
  298. $(echo "${BUNDLE_PLUGINS[@]/#/-x }") \
  299. -x ./OBS.app/Contents/PlugIns/obs-browser-page
  300. fi
  301. step "Move libobs-opengl to final destination"
  302. if [ -f "./libobs-opengl/libobs-opengl.so" ]; then
  303. /bin/cp ./libobs-opengl/libobs-opengl.so ./OBS.app/Contents/Frameworks
  304. else
  305. /bin/cp ./libobs-opengl/${BUILD_CONFIG}/libobs-opengl.so ./OBS.app/Contents/Frameworks
  306. fi
  307. step "Copy QtNetwork for plugin support"
  308. /bin/cp -R /tmp/obsdeps/lib/QtNetwork.framework ./OBS.app/Contents/Frameworks
  309. /bin/chmod -R +w ./OBS.app/Contents/Frameworks/QtNetwork.framework
  310. /bin/rm -r ./OBS.app/Contents/Frameworks/QtNetwork.framework/Headers
  311. /bin/rm -r ./OBS.app/Contents/Frameworks/QtNetwork.framework/Versions/5/Headers/
  312. /bin/chmod 644 ./OBS.app/Contents/Frameworks/QtNetwork.framework/Versions/5/Resources/Info.plist
  313. install_name_tool -id @executable_path/../Frameworks/QtNetwork.framework/Versions/5/QtNetwork ./OBS.app/Contents/Frameworks/QtNetwork.framework/Versions/5/QtNetwork
  314. 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
  315. }
  316. install_frameworks() {
  317. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  318. if [ ! -d ./OBS.app ]; then
  319. error "No OBS.app bundle found"
  320. exit 1
  321. fi
  322. hr "Adding Chromium Embedded Framework"
  323. step "Copy Framework..."
  324. /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/
  325. }
  326. prepare_macos_bundle() {
  327. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  328. if [ ! -d ./rundir/${BUILD_CONFIG}/bin ]; then
  329. error "No OBS build found"
  330. return
  331. fi
  332. if [ -d ./OBS.app ]; then /bin/rm -rf ./OBS.app; fi
  333. hr "Preparing OBS.app bundle"
  334. step "Copy binary and plugins..."
  335. /bin/mkdir -p OBS.app/Contents/MacOS
  336. /bin/mkdir OBS.app/Contents/PlugIns
  337. /bin/mkdir OBS.app/Contents/Resources
  338. /bin/mkdir OBS.app/Contents/Frameworks
  339. /bin/cp rundir/${BUILD_CONFIG}/bin/obs ./OBS.app/Contents/MacOS
  340. /bin/cp rundir/${BUILD_CONFIG}/bin/obs-ffmpeg-mux ./OBS.app/Contents/MacOS
  341. /bin/cp rundir/${BUILD_CONFIG}/bin/libobsglad.0.dylib ./OBS.app/Contents/MacOS
  342. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  343. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper.app" "./OBS.app/Contents/Frameworks/OBS Helper.app"
  344. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper (GPU).app" "./OBS.app/Contents/Frameworks/OBS Helper (GPU).app"
  345. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper (Plugin).app" "./OBS.app/Contents/Frameworks/OBS Helper (Plugin).app"
  346. /bin/cp -R "rundir/${BUILD_CONFIG}/bin/OBS Helper (Renderer).app" "./OBS.app/Contents/Frameworks/OBS Helper (Renderer).app"
  347. fi
  348. /bin/cp -R rundir/${BUILD_CONFIG}/data ./OBS.app/Contents/Resources
  349. /bin/cp ${CI_SCRIPTS}/app/AppIcon.icns ./OBS.app/Contents/Resources
  350. /bin/cp -R rundir/${BUILD_CONFIG}/obs-plugins/ ./OBS.app/Contents/PlugIns
  351. /bin/cp ${CI_SCRIPTS}/app/Info.plist ./OBS.app/Contents
  352. # Scripting plugins are required to be placed in same directory as binary
  353. if [ -d ./OBS.app/Contents/Resources/data/obs-scripting ]; then
  354. /bin/mv ./OBS.app/Contents/Resources/data/obs-scripting/obslua.so ./OBS.app/Contents/MacOS/
  355. /bin/mv ./OBS.app/Contents/Resources/data/obs-scripting/_obspython.so ./OBS.app/Contents/MacOS/
  356. /bin/mv ./OBS.app/Contents/Resources/data/obs-scripting/obspython.py ./OBS.app/Contents/MacOS/
  357. /bin/rm -rf ./OBS.app/Contents/Resources/data/obs-scripting/
  358. fi
  359. bundle_dylibs
  360. install_frameworks
  361. /bin/cp ${CI_SCRIPTS}/app/OBSPublicDSAKey.pem ./OBS.app/Contents/Resources
  362. step "Set bundle meta information..."
  363. /usr/bin/plutil -insert CFBundleVersion -string ${GIT_TAG}-${GIT_HASH} ./OBS.app/Contents/Info.plist
  364. /usr/bin/plutil -insert CFBundleShortVersionString -string ${GIT_TAG}-${GIT_HASH} ./OBS.app/Contents/Info.plist
  365. /usr/bin/plutil -insert OBSFeedsURL -string https://obsproject.com/osx_update/feeds.xml ./OBS.app/Contents/Info.plist
  366. /usr/bin/plutil -insert SUFeedURL -string https://obsproject.com/osx_update/stable/updates.xml ./OBS.app/Contents/Info.plist
  367. /usr/bin/plutil -insert SUPublicDSAKeyFile -string OBSPublicDSAKey.pem ./OBS.app/Contents/Info.plist
  368. }
  369. ## CREATE MACOS DISTRIBUTION AND INSTALLER IMAGE ##
  370. prepare_macos_image() {
  371. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  372. if [ ! -d ./OBS.app ]; then
  373. error "No OBS.app bundle found"
  374. return
  375. fi
  376. hr "Preparing macOS installation image"
  377. if [ -f "${FILE_NAME}" ]; then
  378. /bin/rm "${FILE_NAME}"
  379. fi
  380. step "Run dmgbuild..."
  381. /bin/cp "${CI_SCRIPTS}/package/settings.json.template" ./settings.json
  382. /usr/bin/sed -i '' 's#\$\$VERSION\$\$#'"${GIT_TAG}"'#g' ./settings.json
  383. /usr/bin/sed -i '' 's#\$\$CI_PATH\$\$#'"${CI_SCRIPTS}"'#g' ./settings.json
  384. /usr/bin/sed -i '' 's#\$\$BUNDLE_PATH\$\$#'"${CHECKOUT_DIR}"'/build#g' ./settings.json
  385. /bin/echo -n "${COLOR_ORANGE}"
  386. dmgbuild "OBS-Studio ${GIT_TAG}" "${FILE_NAME}" -s ./settings.json
  387. /bin/echo -n "${COLOR_RESET}"
  388. if [ -n "${CODESIGN_OBS}" ]; then
  389. codesign_image
  390. fi
  391. }
  392. ## SET UP CODE SIGNING AND NOTARIZATION CREDENTIALS ##
  393. ##############################################################################
  394. # Apple Developer Identity needed:
  395. #
  396. # + Signing the code requires a developer identity in the system's keychain
  397. # + codesign will look up and find the identity automatically
  398. #
  399. ##############################################################################
  400. read_codesign_ident() {
  401. if [ ! -n "${CODESIGN_IDENT}" ]; then
  402. step "Code-signing Setup"
  403. /usr/bin/read -p "${COLOR_ORANGE} + Apple developer identity: ${COLOR_RESET}" CODESIGN_IDENT
  404. fi
  405. }
  406. ##############################################################################
  407. # Apple Developer credentials necessary:
  408. #
  409. # + Signing for distribution and notarization require an active Apple
  410. # Developer membership
  411. # + An Apple Development identity is needed for code signing
  412. # (i.e. 'Apple Development: YOUR APPLE ID (PROVIDER)')
  413. # + Your Apple developer ID is needed for notarization
  414. # + An app-specific password is necessary for notarization from CLI
  415. # + This password will be stored in your macOS keychain under the identifier
  416. # 'OBS-Codesign-Password'with access Apple's 'altool' only.
  417. ##############################################################################
  418. read_codesign_pass() {
  419. if [ ! -n "${CODESIGN_IDENT_PASS}" ]; then
  420. step "Notarization Setup"
  421. /usr/bin/read -p "${COLOR_ORANGE} + Apple account id: ${COLOR_RESET}" CODESIGN_IDENT_USER
  422. CODESIGN_IDENT_PASS=$(stty -echo; /usr/bin/read -p "${COLOR_ORANGE} + Apple developer password: ${COLOR_RESET}" pwd; stty echo; /bin/echo $pwd)
  423. /bin/echo -n "${COLOR_ORANGE}"
  424. /usr/bin/xcrun altool --store-password-in-keychain-item "OBS-Codesign-Password" -u "${CODESIGN_IDENT_USER}" -p "${CODESIGN_IDENT_PASS}"
  425. /bin/echo -n "${COLOR_RESET}"
  426. CODESIGN_IDENT_SHORT=$(/bin/echo "${CODESIGN_IDENT}" | /usr/bin/sed -En "s/.+\((.+)\)/\1/p")
  427. fi
  428. }
  429. codesign_bundle() {
  430. if [ ! -n "${CODESIGN_OBS}" ]; then step "Skipping application bundle code signing"; return; fi
  431. ensure_dir "${CHECKOUT_DIR}/${BUILD_DIR}"
  432. trap "caught_error 'code-signing app'" ERR
  433. if [ ! -d ./OBS.app ]; then
  434. error "No OBS.app bundle found"
  435. return
  436. fi
  437. hr "Code-signing application bundle"
  438. /usr/bin/xattr -crs ./OBS.app
  439. read_codesign_ident
  440. step "Code-sign Sparkle framework..."
  441. /bin/echo -n "${COLOR_ORANGE}"
  442. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app/Contents/MacOS/fileop"
  443. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app/Contents/MacOS/Autoupdate"
  444. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" --deep ./OBS.app/Contents/Frameworks/Sparkle.framework
  445. /bin/echo -n "${COLOR_RESET}"
  446. step "Code-sign CEF framework..."
  447. /bin/echo -n "${COLOR_ORANGE}"
  448. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libEGL.dylib"
  449. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libswiftshader_libEGL.dylib"
  450. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libGLESv2.dylib"
  451. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libswiftshader_libGLESv2.dylib"
  452. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  453. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libvk_swiftshader.dylib"
  454. fi
  455. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" --deep "./OBS.app/Contents/Frameworks/Chromium Embedded Framework.framework"
  456. /bin/echo -n "${COLOR_RESET}"
  457. step "Code-sign DAL Plugin..."
  458. /bin/echo -n "${COLOR_ORANGE}"
  459. /usr/bin/codesign --force --options runtime --deep --sign "${CODESIGN_IDENT}" "./OBS.app/Contents/Resources/data/obs-mac-virtualcam.plugin"
  460. /bin/echo -n "${COLOR_RESET}"
  461. step "Code-sign OBS code..."
  462. /bin/echo -n "${COLOR_ORANGE}"
  463. /usr/bin/codesign --force --options runtime --entitlements "${CI_SCRIPTS}/app/entitlements.plist" --sign "${CODESIGN_IDENT}" --deep ./OBS.app
  464. /bin/echo -n "${COLOR_RESET}"
  465. if ! [ "${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}}" -le 3770 ]; then
  466. step "Code-sign CEF helper apps..."
  467. /bin/echo -n "${COLOR_ORANGE}"
  468. /usr/bin/codesign --force --options runtime --sign "${CODESIGN_IDENT}" --deep "./OBS.app/Contents/Frameworks/OBS Helper.app"
  469. /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"
  470. /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"
  471. /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"
  472. /bin/echo -n "${COLOR_RESET}"
  473. fi
  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 $*