tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

wr-macos-cross-build-setup.sh (2985B)


      1 #!/bin/bash
      2 set -x -e -v
      3 
      4 export TARGET_TRIPLE="x86_64-apple-darwin"
      5 
      6 MACOS_SYSROOT=$(ls -d $MOZ_FETCHES_DIR/MacOSX*.sdk)
      7 CLANGDIR="${MOZ_FETCHES_DIR}/clang"
      8 
      9 # Deploy the wrench dependencies
     10 mv ${MOZ_FETCHES_DIR}/wrench-deps/{vendor,.cargo} "${GECKO_PATH}/gfx/wr/"
     11 
     12 # Building wrench with the `headless` feature also builds the osmesa-src crate,
     13 # which includes building C++ code. We have to do a bunch of shenanigans
     14 # to make this cross-compile properly.
     15 
     16 pushd "${MOZ_FETCHES_DIR}/clang/bin"
     17 
     18 # Add a pkg-config cross-compile wrapper. Without this, the configure script
     19 # will use pkg-config from the host, which will find host libraries that are
     20 # not what we want. This script stolen from
     21 # https://autotools.io/pkgconfig/cross-compiling.html
     22 cat > ${TARGET_TRIPLE}-pkg-config <<END_PKGCONFIG_WRAPPER
     23 #!/bin/sh
     24 export PKG_CONFIG_DIR=
     25 export PKG_CONFIG_LIBDIR=${MACOS_SYSROOT}/usr/lib/pkgconfig:${MACOS_SYSROOT}/usr/share/pkgconfig
     26 export PKG_CONFIG_SYSROOT_DIR=${MACOS_SYSROOT}
     27 exec pkg-config "\$@"
     28 END_PKGCONFIG_WRAPPER
     29 chmod +x "${TARGET_TRIPLE}-pkg-config"
     30 popd
     31 
     32 [ -d "${MOZ_FETCHES_DIR}/clang-mac/clang" ] && cat > ${MOZ_FETCHES_DIR}/clang-mac/clang/bin/llvm-config <<EOF_LLVM_CONFIG
     33 #!/bin/sh
     34 ${MOZ_FETCHES_DIR}/clang/bin/llvm-config "\$@" | sed 's,${MOZ_FETCHES_DIR}/clang,${MOZ_FETCHES_DIR}/clang-mac/clang,g;s,-lLLVM-[0-9]\+,-lLLVM,g'
     35 EOF_LLVM_CONFIG
     36 
     37 export PATH="${MOZ_FETCHES_DIR}/rustc/bin:${MOZ_FETCHES_DIR}/clang/bin:${MOZ_FETCHES_DIR}/wrench-deps/meson:${PATH}"
     38 
     39 # Tell the configure script where to find zlib, because otherwise it tries
     40 # to use pkg-config to find it, which fails (no .pc file in the macos SDK).
     41 export ZLIB_CFLAGS="-I${MACOS_SYSROOT}/usr/include"
     42 export ZLIB_LIBS="-L${MACOS_SYSROOT}/usr/lib -lz"
     43 
     44 # Set up compiler and flags for cross-compile. Careful to only export the
     45 # target-specific CFLAGS/CXXFLAGS variables, to not break any host builds.
     46 export CC="${CLANGDIR}/bin/clang"
     47 TARGET_CFLAGS="-fuse-ld=lld -target ${TARGET_TRIPLE} -mmacosx-version-min=10.15 --rtlib=compiler-rt --sysroot ${MACOS_SYSROOT} -Qunused-arguments"
     48 export CFLAGS_${TARGET_TRIPLE//-/_}="${TARGET_CFLAGS}"
     49 export CXX="${CLANGDIR}/bin/clang++"
     50 TARGET_CXXFLAGS="-fuse-ld=lld -target ${TARGET_TRIPLE} -mmacosx-version-min=10.15 --rtlib=compiler-rt --sysroot ${MACOS_SYSROOT} -stdlib=libc++ -Qunused-arguments"
     51 export CXXFLAGS_${TARGET_TRIPLE//-/_}="${TARGET_CXXFLAGS}"
     52 export AR="${CLANGDIR}/bin/llvm-ar"
     53 
     54 # See documentation in cargo-linker for why we need this. TL;DR is that passing
     55 # the right arguments to the linker when invoked by cargo is nigh impossible
     56 # without this.
     57 export MOZ_CARGO_WRAP_LD="${CC}"
     58 export MOZ_CARGO_WRAP_LD_CXX="${CXX}"
     59 export MOZ_CARGO_WRAP_LDFLAGS="${TARGET_CFLAGS}"
     60 export CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="${GECKO_PATH}/build/cargo-linker"
     61 
     62 # Ensure that any dependencies which use bindgen pass the correct
     63 # sysroot. Specificlly, this is needed to compile mozangle.
     64 export BINDGEN_EXTRA_CLANG_ARGS="--sysroot ${MACOS_SYSROOT}"