name: MacOS. on: push: paths-ignore: - 'docs/**' - '**.md' - 'changelog.txt' - 'LEGAL' - 'LICENSE' - '.github/**' - '!.github/workflows/mac.yml' - 'lib/xdg/**' - 'snap/**' - 'Telegram/build/docker/**' - 'Telegram/Resources/uwp/**' - 'Telegram/Resources/winrc/**' - 'Telegram/SourceFiles/platform/win/**' - 'Telegram/SourceFiles/platform/linux/**' - 'Telegram/configure.bat' pull_request: paths-ignore: - 'docs/**' - '**.md' - 'changelog.txt' - 'LEGAL' - 'LICENSE' - '.github/**' - '!.github/workflows/mac.yml' - 'lib/xdg/**' - 'snap/**' - 'Telegram/build/docker/**' - 'Telegram/Resources/uwp/**' - 'Telegram/Resources/winrc/**' - 'Telegram/SourceFiles/platform/win/**' - 'Telegram/SourceFiles/platform/linux/**' - 'Telegram/configure.bat' jobs: macos: name: MacOS runs-on: ${{ (github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/nightly') && 'depot-macos-latest' || 'macos-latest' }} strategy: matrix: defines: - "" env: UPLOAD_ARTIFACT: "true" ONLY_CACHE: "false" PREPARE_PATH: "Telegram/build/prepare/prepare.py" steps: - name: Get repository name. run: echo "REPO_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV - name: Clone. uses: actions/checkout@v6 with: submodules: recursive path: ${{ env.REPO_NAME }} - name: First set up. run: | sudo chown -R `whoami`:admin /usr/local/share brew update brew upgrade || true brew install automake meson nasm ninja pkg-config # Disable spotlight. sudo mdutil -a -i off sudo xcode-select -s /Applications/Xcode.app/Contents/Developer - name: Libraries cache. id: cache-libs uses: actions/cache@v5 with: path: | Libraries ThirdParty key: ${{ runner.OS }}-libs-${{ hashFiles(format('{0}/{1}', env.REPO_NAME, env.PREPARE_PATH)) }} restore-keys: ${{ runner.OS }}-libs- - name: Libraries. run: | ./$REPO_NAME/Telegram/build/prepare/mac.sh skip-release silent - name: Free up some disk space. run: find Libraries '(' '(' ! '(' -name '*.a' -o -name '*.h' -o -name '*.hpp' -o -name '*.inc' -o -name '*.cmake' -o -path '*/include/*' -o -path '*/objects-*' -o -path '*/cache_keys/*' -o -path '*/patches/*' -o -perm +111 ')' -type f ')' -o -empty ')' -delete - name: Telegram Desktop build. if: env.ONLY_CACHE == 'false' run: | cd $REPO_NAME/Telegram DEFINE="" if [ -n "${{ matrix.defines }}" ]; then DEFINE="-D ${{ matrix.defines }}=ON" echo Define from matrix: $DEFINE echo "ARTIFACT_NAME=Telegram ${{ matrix.defines }}" >> $GITHUB_ENV else echo "ARTIFACT_NAME=Telegram" >> $GITHUB_ENV fi ./configure.sh \ -D CMAKE_CONFIGURATION_TYPES=Debug \ -D CMAKE_OSX_ARCHITECTURES=x86_64 \ -D CMAKE_COMPILE_WARNING_AS_ERROR=ON \ -D CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED=NO \ -D CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT=dwarf-with-dsym \ -D CMAKE_XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS=YES \ -D CMAKE_XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING=NO \ -D CMAKE_XCODE_ATTRIBUTE_STRIP_INSTALLED_PRODUCT=NO \ -D CMAKE_XCODE_ATTRIBUTE_ENABLE_ADDRESS_SANITIZER=YES \ -D TDESKTOP_API_TEST=ON \ -D DESKTOP_APP_DISABLE_AUTOUPDATE=ON \ -D DESKTOP_APP_DISABLE_CRASH_REPORTS=OFF \ $DEFINE cmake --build ../out --config Debug --parallel - name: Bundle AddressSanitizer runtime into the app. if: env.UPLOAD_ARTIFACT == 'true' run: | cd $REPO_NAME/out/Debug APP=Telegram.app BIN="$APP/Contents/MacOS/Telegram" FRAMEWORKS="$APP/Contents/Frameworks" # Fail loudly if ASan did not actually get linked into the binary. ASAN_IN_BIN=$(otool -L "$BIN" | awk '/libclang_rt.asan/ {print $1; exit}') if [ -z "$ASAN_IN_BIN" ]; then echo "Binary is not linked against the ASan runtime." >&2 exit 1 fi echo "Binary references ASan runtime as: $ASAN_IN_BIN" ASAN_DYLIB=$(find "$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang" \ -name 'libclang_rt.asan_osx_dynamic.dylib' | head -n1) if [ -z "$ASAN_DYLIB" ]; then echo "AddressSanitizer runtime dylib not found in the toolchain." >&2 exit 1 fi echo "Using ASan runtime: $ASAN_DYLIB" mkdir -p "$FRAMEWORKS" cp "$ASAN_DYLIB" "$FRAMEWORKS/" # Normalize the load command to @rpath form (older clang may embed an # absolute toolchain path that does not exist on the user's machine). if [ "$ASAN_IN_BIN" != "@rpath/libclang_rt.asan_osx_dynamic.dylib" ]; then install_name_tool -change "$ASAN_IN_BIN" \ @rpath/libclang_rt.asan_osx_dynamic.dylib "$BIN" fi # Add an rpath that resolves inside the bundle on the user's machine. install_name_tool -add_rpath @executable_path/../Frameworks "$BIN" # Re-sign (ad-hoc) after the load-command edit. codesign --force --sign - "$FRAMEWORKS/libclang_rt.asan_osx_dynamic.dylib" codesign --force --sign - "$BIN" echo "ASan load command:" otool -L "$BIN" | grep asan || true - name: Move artifact. if: env.UPLOAD_ARTIFACT == 'true' run: | cd $REPO_NAME/out/Debug mkdir artifact mv Telegram.app artifact/ mv Telegram.app.dSYM artifact/ mv Updater artifact/ - uses: actions/upload-artifact@v7 if: env.UPLOAD_ARTIFACT == 'true' name: Upload artifact. with: name: ${{ env.ARTIFACT_NAME }} path: ${{ env.REPO_NAME }}/out/Debug/artifact/