code:
#!/bin/bash
[% c("var/set_default_env") -%]
builddir=/var/tmp/build
mkdir $builddir
distdir=/var/tmp/dist/[% project %]
mkdir -p "$distdir"
tar -C /var/tmp/dist -xf [% c('input_files_by_name/cmake') %]
tar -C /var/tmp/dist -xf [% c('input_files_by_name/ninja') %]
tar -C /var/tmp/dist -xf [% c('input_files_by_name/clang') %]
tar -C $distdir -xf [% c('input_files_by_name/SDK') %]
tar -C $distdir -xf [% c('input_files_by_name/cctools') %]
tar -C $builddir -xf [% c('input_files_by_name/llvm-project') %]

arch=x86_64
clangdir=/var/tmp/dist/clang/bin
cctoolsdir=$distdir/cctools/bin
sysrootdir=$distdir/MacOSX[% c("version") %].sdk/
target=x86_64-apple-darwin
# We still need to put the cctoolsdir on the path. That's because of `lipo`. See
# the respective comment in the cctools build script.
export PATH="/var/tmp/dist/ninja:/var/tmp/dist/cmake/bin:$cctoolsdir:$PATH"
export MACOSX_DEPLOYMENT_TARGET=[% c("var/macosx_deployment_target") %]
export MACH_USE_SYSTEM_PYTHON=1

cd $builddir/clang-source
patch -p1 < $rootdir/compiler-rt-cross-compile.patch
patch -p1 < $rootdir/compiler-rt-no-codesign.patch
cd ..
mkdir build_clang
pushd build_clang
# We follow quite closely Mozilla's build/build-clang/build-clang.py with the
# clang-macosx64.json flavor.
cmake -GNinja \
      -DCMAKE_C_COMPILER=$clangdir/clang \
      -DCMAKE_CXX_COMPILER=$clangdir/clang++ \
      -DCMAKE_ASM_COMPILER=$clangdir/clang \
      -DCMAKE_LINKER=$clangdir/clang \
      -DCMAKE_AR=$cctoolsdir/$target-ar \
      -DCMAKE_C_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
      -DCMAKE_CXX_FLAGS="-stdlib=libc++ [% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
      -DCMAKE_ASM_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
      -DCMAKE_EXE_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
      -DCMAKE_SHARED_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=$distdir/clang \
      -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \
      -DLLVM_ENABLE_ASSERTIONS=OFF \
      -DPYTHON_EXECUTABLE=/usr/bin/python3 \
      -DLLVM_TOOL_LIBCXX_BUILD=ON \
      -DLLVM_ENABLE_BINDINGS=OFF \
      -DLLVM_ENABLE_LIBXML2=FORCE_ON \
      -DLLVM_LINK_LLVM_DYLIB=ON \
      -DCMAKE_RANLIB=$cctoolsdir/$target-ranlib \
      -DCMAKE_LIBTOOL=$cctoolsdir/$target-libtool \
      -DCMAKE_SYSTEM_NAME=Darwin \
      -DCMAKE_SYSTEM_VERSION=$MACOSX_DEPLOYMENT_TARGET \
      -DLLVM_ENABLE_THREADS=OFF \
      -DCOMPILER_RT_BUILD_XRAY=OFF \
      -DLIBCXXABI_LIBCXX_INCLUDES=$builddir/clang-source/projects/libcxx/include \
      -DCMAKE_OSX_SYSROOT=$sysrootdir \
      -DCMAKE_FIND_ROOT_PATH=$sysrootdir \
      -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
      -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
      -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
      -DCMAKE_MACOSX_RPATH=ON \
      -DCMAKE_OSX_ARCHITECTURES=$arch \
      -DDARWIN_macosx_OVERRIDE_SDK_VERSION=$MACOSX_DEPLOYMENT_TARGET \
      -DDARWIN_osx_ARCHS=$arch \
      -DDARWIN_osx_SYSROOT=$sysrootdir \
      -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-apple-darwin $builddir/clang-source/llvm

ninja install -v

popd
mkdir build_compiler_rt
pushd build_compiler_rt

# And we build compiler-rt by following taskcluster/scripts/misc/build-compiler-rt.sh.
cmake -GNinja \
      -DCMAKE_C_COMPILER=$clangdir/clang \
      -DCMAKE_CXX_COMPILER=$clangdir/clang++ \
      -DCMAKE_C_COMPILER_TARGET=$target \
      -DCMAKE_CXX_COMPILER_TARGET=$target \
      -DCMAKE_ASM_COMPILER_TARGET=$target \
      -DCMAKE_AR=$clangdir/llvm-ar \
      -DCMAKE_RANLIB=$clangdir/llvm-ranlib \
      -DCMAKE_C_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
      -DCMAKE_CXX_FLAGS="-stdlib=libc++ [% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
      -DCMAKE_ASM_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
      -DCMAKE_EXE_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
      -DCMAKE_SHARED_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
      -DCMAKE_BUILD_TYPE=Release \
      -DLLVM_ENABLE_ASSERTIONS=OFF \
      -DCMAKE_INSTALL_PREFIX=$distdir/clang/lib/clang/[% pc("clang", "version") %]/ \
      -DLLVM_CONFIG_PATH=$clangdir/llvm-config \
      -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
      -DCMAKE_LINKER=$cctoolsdir/$target-ld \
      -DCMAKE_LIPO=$cctoolsdir/lipo \
      -DCMAKE_SYSTEM_NAME=Darwin \
      -DCMAKE_SYSTEM_VERSION=$MACOSX_DEPLOYMENT_TARGET \
      -DDARWIN_macosx_OVERRIDE_SDK_VERSION=$MACOSX_DEPLOYMENT_TARGET \
      -DDARWIN_osx_ARCHS=$arch \
      -DDARWIN_osx_SYSROOT=$sysrootdir \
      -DDARWIN_osx_BUILTIN_ARCHS=$arch \
      -DCMAKE_OSX_SYSROOT=$sysrootdir \
      -DCMAKE_FIND_ROOT_PATH=$sysrootdir \
      -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
      -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
      -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
      -DDARWIN_osx_BUILTIN_ARCHS=$arch \
      $builddir/clang-source/compiler-rt

ninja install -v

# We now have a native macosx64 toolchain.
# What we want is a native linux64 toolchain which can target macosx64.
# Overlay the linux64 toolchain that we used for this build. Note: we don't do
# any ASan builds for macOS (yet). Once we do that we need to preserve at least
# `llvm-symbolizer` as that one seems to get shipped with sanitizer builds (at
# least that's what Mozilla claims).
cd $distdir
cp --remove-destination -lr /var/tmp/dist/clang/* clang/

cd cctools/bin
ln -s ../../clang/bin/clang x86_64-apple-darwin-clang
ln -s ../../clang/bin/clang++ x86_64-apple-darwin-clang++

cd /var/tmp/dist
[% c('tar', {
   tar_src => [ project ],
   tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
}) %]

path: projects/macosx-toolchain/build


code:
Add `-target x86_64-apple-darwin' to the compiler-rt overridden CFLAGS

diff --git a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
index 28d398672..aac68bf36 100644
--- a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
@@ -265,7 +265,7 @@ endfunction()
 macro(darwin_add_builtin_libraries)
   set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes)

-  set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer")
+  set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer -target x86_64-apple-darwin -isysroot ${CMAKE_OSX_SYSROOT} -I${CMAKE_OSX_SYSROOT}/usr/include")
   set(CMAKE_C_FLAGS "")
   set(CMAKE_CXX_FLAGS "")
   set(CMAKE_ASM_FLAGS "")

repo_name: JeremyRand/tor

license: mit


code:
Disable codesign for macosx cross-compile toolchain. Codesign only works on OSX.

Index: cmake/Modules/AddCompilerRT.cmake
===================================================================
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -321,14 +321,6 @@
         set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
         set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
       endif()
-      if(APPLE)
-        # Ad-hoc sign the dylibs
-        add_custom_command(TARGET ${libname}
-          POST_BUILD
-          COMMAND codesign --sign - $<TARGET_FILE:${libname}>
-          WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
-        )
-      endif()
     endif()

     set(parent_target_arg)


code:
# vim: filetype=yaml sw=2
filename: '[% project %]-[% c("version") %]-1-[% c("var/build_id") %].tar.gz'
version: 10.12
container:
  use_container: 1
var:
  setup: |
    mkdir -p /var/tmp/dist
    tar -C /var/tmp/dist -xf $rootdir/[% c("compiler_tarfile") %]
    export sysrootdir=/var/tmp/dist/[% project %]/MacOSX[% c("version") %].sdk/
    export clangdir=/var/tmp/dist/[% project %]/clang
    export cctoolsdir=/var/tmp/dist/[% project %]/cctools/bin
    export PATH="$clangdir/bin:$cctoolsdir:$PATH"
    export LD_LIBRARY_PATH=/var/tmp/dist/[% project %]/clang/lib
    export CC="$clangdir/bin/clang [% c('var/FLAGS') %]"
    export LDFLAGS="[% c('var/LDFLAGS') %]"
    export MACOSX_DEPLOYMENT_TARGET=[% c("var/macosx_deployment_target") %]

input_files:
  - project: container-image
  - name: clang
    project: clang
  - name: cctools
    project: cctools
  - name: cmake
    project: cmake
  - name: ninja
    project: ninja
  # Instructions on how to create the SDK tarball can be found at:
  # build/macosx/cross-mozconfig.common
  - name: SDK
    URL: 'https://people.torproject.org/~gk/mirrors/sources/MacOSX[% c("version") %].sdk.tar.bz2'
    sha256sum: d2ef4ae4f85675c08795d33f283e307b6299184d78d4b10bdbea39df6dca7d94
  - name: llvm-project
    project: llvm-project
  - filename: compiler-rt-cross-compile.patch
  - filename: compiler-rt-no-codesign.patch

path: projects/macosx-toolchain/config


code:
#!/bin/bash
[% c("var/set_default_env") -%]

mkdir -p chrome/browser/content/browser/manual
unzip $rootdir/[% c('input_files_by_name/manual') %]
python3 $rootdir/[% c('input_files_by_name/package_script') %] public chrome/browser/content/browser/manual

[% c('tar', {
        tar_src => [ 'chrome' ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
    }) %]

path: projects/manual/build


code:
# vim: filetype=yaml sw=2
# To update, see doc/how-to-update-the-manual.txt
# Remember to update also the package's hash, with the version!
version: 44679
filename: 'manual-[% c("version") %].tar.gz'
container:
  use_container: 1

var:
  container:
    suite: bullseye
    arch: amd64
  deps:
    - python3
    - unzip
  pre_pkginst: ''

input_files:
  - project: container-image
  - URL: 'https://people.torproject.org/~pierov/tbb_files/manual_[% c("version") %].zip'
    name: manual
    sha256sum: d9061ca5afdf4d04fb735bc645318d5eedc69f10fa200faaca82731ad4b105f7
  - filename: packagemanual.py
    name: package_script

path: projects/manual/config


code:
#!/usr/bin/env python3
from pathlib import Path
import re
import sys
import shutil

PAGE_NAME = 'offline-docs'
STATIC_PATH = 'chrome://browser/content/manual/static'

if len(sys.argv) < 3:
    print(f'Usage: {sys.argv[0]} lektor-out-directory target-directory')
    sys.exit(1)

source = Path(sys.argv[1])
target = Path(sys.argv[2])
if not target.exists():
    target.mkdir(exist_ok=True)

static_re = re.compile('"(?:../)*static/([^"]+)"')
link_re = re.compile('href="../([^"]+)"')

def clean_urls(match):
    m = re.match(r'(?:../)?([^/#]+)[/]?[#]?(.*)', match.group(1))
    slug = m.group(1)
    if m.group(2):
        anchor = '_' + m.group(2)
    else:
        anchor = ''
    return f'href="#{slug}{anchor}"'

htmls = source.rglob(f'{PAGE_NAME}/index.html')
for page in htmls:
    with page.open(encoding='utf8') as f:
        contents = f.read()
    contents = static_re.sub(f'"{STATIC_PATH}/\\1"', contents)
    contents = link_re.sub(clean_urls, contents)

    rel = page.relative_to(source)
    dest_name = str(list(rel.parents)[-2].name)
    if dest_name == PAGE_NAME:
        dest_name = 'en'
    dest_name += '.html'
    with (target / dest_name).open('w', encoding='utf8') as f:
        f.write(contents)

shutil.rmtree(target / 'static', ignore_errors=True)
shutil.copytree(source / 'static', target / 'static')


code:
#!/bin/bash
[% c("var/set_default_env") -%]
builddir=/var/tmp/build
distdir=/var/tmp/dist/mingw-w64-clang
mkdir -p $distdir
cd /var/tmp/dist
tar -xf $rootdir/[% c('input_files_by_name/clang') %]
mv clang/* mingw-w64-clang/
tar -xf $rootdir/[% c('input_files_by_name/cmake') %]
mkdir -p $builddir
cd $builddir
tar -xf $rootdir/mingw-w64-clang-[% c('version') %].tar.gz
mv mingw-w64-clang-[% c('version') %] mingw-w64-clang
tar -xf $rootdir/[% c('input_files_by_name/llvm-project') %]
tar -xf $rootdir/[% c('input_files_by_name/llvm-mingw') %]

# Adding the wrappers and symlinks we need
cd $distdir/bin
exception_flags=""
[% IF c("var/windows-i686") %]
  exception_flags="-fsjlj-exceptions"
[% END -%]
compiler_flags="--sysroot \$DIR/../[% c("arch") %]-w64-mingw32 -rtlib=compiler-rt -stdlib=libc++ -fuse-ld=lld $exception_flags -fuse-cxa-atexit -Qunused-arguments"

cat <<EOF >[% c("arch") %]-w64-mingw32-clang
#!/bin/sh
DIR="\$(cd "\$(dirname "\$0")" && pwd)"
\$DIR/clang -target [% c("arch") %]-w64-mingw32 $compiler_flags "\$@"
EOF
chmod +x [% c("arch") %]-w64-mingw32-clang

cat <<EOF >[% c("arch") %]-w64-mingw32-clang++
#!/bin/sh
DIR="\$(cd "\$(dirname "\$0")" && pwd)"
\$DIR/clang -target [% c("arch") %]-w64-mingw32 --driver-mode=g++ $compiler_flags "\$@"
EOF
chmod +x [% c("arch") %]-w64-mingw32-clang++

ln -s llvm-nm [% c("arch") %]-w64-mingw32-nm
ln -s llvm-strip [% c("arch") %]-w64-mingw32-strip
ln -s llvm-readobj [% c("arch") %]-w64-mingw32-readobj
ln -s llvm-objcopy [% c("arch") %]-w64-mingw32-objcopy
./clang $builddir/llvm-mingw/wrappers/windres-wrapper.c -O2 -Wl,-s -o [% c("arch") %]-w64-mingw32-windres

# Building mingw-w64
export PATH="$distdir/bin:/var/tmp/dist/cmake/bin:$PATH"
CC="[% c("arch") %]-w64-mingw32-clang"
CXX="[% c("arch") %]-w64-mingw32-clang++"
# This is the default value of _WIN32_WINNT. Gecko configure script explicitly
# sets this, so this is not used to build Gecko itself. We default to 0x601,
# which is Windows 7.
default_win32_winnt=0x601
[% IF c("var/windows-i686") %]
  crt_flags="--enable-lib32 --disable-lib64"
  compiler_rt_machine="i386"
[% ELSE -%]
  crt_flags="--disable-lib32 --enable-lib64"
  compiler_rt_machine="x86_64"
[% END -%]

cd $builddir/mingw-w64-clang
patch -p1 < $rootdir/mingw-winrt.patch
patch -p1 < $rootdir/mingw-dwrite_3.patch
patch -p1 < $rootdir/mingw-unknown.patch

cd mingw-w64-headers
mkdir build && cd build
../configure --host=[% c("arch") %]-w64-mingw32 \
             --enable-sdk=all \
             --enable-idl \
             --with-default-msvcrt=ucrt \
             --with-default-win32-winnt=$default_win32_winnt \
             --prefix=$distdir/[% c("arch") %]-w64-mingw32
make -j[% c("num_procs") %] install

cd $builddir/mingw-w64-clang/mingw-w64-crt
mkdir build && cd build
../configure --host=[% c("arch") %]-w64-mingw32 \
             $crt_flags \
             --with-default-msvcrt=ucrt \
             CC="$CC" \
             AR=llvm-ar \
             RANLIB=llvm-ranlib \
             DLLTOOL=llvm-dlltool \
             --prefix=$distdir/[% c("arch") %]-w64-mingw32
make -j[% c("num_procs") %]
make -j[% c("num_procs") %] install

cd $builddir/mingw-w64-clang/mingw-w64-tools/widl
mkdir build && cd build
../configure --target=[% c("arch") %]-w64-mingw32 --prefix=$distdir
make -j[% c("num_procs") %]
make -j[% c("num_procs") %] install

# compiler-rt
cd $builddir/clang-source/compiler-rt
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_C_COMPILER=$CC \
      -DCMAKE_SYSTEM_NAME=Windows \
      -DCMAKE_AR=$distdir/bin/llvm-ar \
      -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
      -DCMAKE_C_COMPILER_WORKS=1 \
      -DCMAKE_C_COMPILER_TARGET=$compiler_rt_machine-windows-gnu \
      -DCOMPILER_RT_DEFAULT_TARGET_ONLY=TRUE \
      $builddir/clang-source/compiler-rt/lib/builtins
  make -j[% c("num_procs") %]
  rtdir=$distdir/lib/clang/[% pc("llvm-project", "version") %]/lib/windows
  mkdir -p $rtdir
  cp lib/windows/libclang_rt.builtins-$compiler_rt_machine.a $rtdir/

# libunwind
cd $builddir/clang-source/libunwind
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=$distdir/[% c("arch") %]-w64-mingw32 \
      -DCMAKE_C_COMPILER=$CC \
      -DCMAKE_CXX_COMPILER=$CXX \
      -DCMAKE_CROSSCOMPILING=TRUE \
      -DCMAKE_SYSROOT=$distdir/[% c("arch") %]-w64-mingw32 \
      -DCMAKE_SYSTEM_NAME=Windows \
      -DCMAKE_C_COMPILER_WORKS=TRUE \
      -DCMAKE_CXX_COMPILER_WORKS=TRUE \
      -DLLVM_COMPILER_CHECKED=True \
      -DCMAKE_AR=$distdir/bin/llvm-ar \
      -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
      -DLLVM_NO_OLD_LIBSTDCXX=TRUE \
      -DCXX_SUPPORTS_CXX11=TRUE \
      -DCXX_SUPPORTS_CXX_STD=True \
      -DLIBUNWIND_USE_COMPILER_RT=TRUE \
      -DLIBUNWIND_ENABLE_THREADS=TRUE \
      -DLIBUNWIND_ENABLE_SHARED=FALSE \
      -DLIBUNWIND_ENABLE_CROSS_UNWINDING=FALSE \
      -DCMAKE_CXX_FLAGS="-Wno-dll-attribute-on-redeclaration -nostdinc++ -I$builddir/clang-source/libcxx/include -DPSAPI_VERSION=2" \
      -DCMAKE_C_FLAGS="-Wno-dll-attribute-on-redeclaration" \
      $builddir/clang-source/libunwind
make -j[% c("num_procs") %]
make -j[% c("num_procs") %] install

# libcxxabi
cd $builddir/clang-source/libcxxabi
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=$distdir/[% c("arch") %]-w64-mingw32 \
      -DCMAKE_C_COMPILER=$CC \
      -DCMAKE_CXX_COMPILER=$CXX \
      -DCMAKE_CROSSCOMPILING=TRUE \
      -DCMAKE_SYSTEM_NAME=Windows \
      -DCMAKE_C_COMPILER_WORKS=TRUE \
      -DCMAKE_CXX_COMPILER_WORKS=TRUE \
      -DCMAKE_SYSROOT=$distdir/[% c("arch") %]-w64-mingw32 \
      -DLLVM_COMPILER_CHECKED=True \
      -DCMAKE_AR=$distdir/bin/llvm-ar \
      -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
      -DLIBCXXABI_USE_COMPILER_RT=ON \
      -DLIBCXXABI_ENABLE_EXCEPTIONS=ON \
      -DLIBCXXABI_ENABLE_THREADS=ON \
      -DLIBCXXABI_TARGET_TRIPLE=[% c("arch") %]-w64-mingw32 \
      -DLIBCXXABI_ENABLE_SHARED=OFF \
      -DLIBCXXABI_LIBCXX_INCLUDES=$builddir/clang-source/libcxx/include \
      -DLLVM_NO_OLD_LIBSTDCXX=TRUE \
      -DCXX_SUPPORTS_CXX11=TRUE \
      -DCXX_SUPPORTS_CXX_STD=True \
      -DCMAKE_CXX_FLAGS="-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_HAS_THREAD_API_WIN32" \
      $builddir/clang-source/libcxxabi
make -j[% c("num_procs") %] VERBOSE=1

# libcxx
cd $builddir/clang-source/libcxx
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=$distdir/[% c("arch") %]-w64-mingw32 \
      -DCMAKE_C_COMPILER=$CC \
      -DCMAKE_CXX_COMPILER=$CXX \
      -DCMAKE_CROSSCOMPILING=TRUE \
      -DCMAKE_SYSTEM_NAME=Windows \
      -DCMAKE_C_COMPILER_WORKS=TRUE \
      -DCMAKE_CXX_COMPILER_WORKS=TRUE \
      -DLLVM_COMPILER_CHECKED=True \
      -DCMAKE_AR=$distdir/bin/llvm-ar \
      -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
      -DLIBCXX_USE_COMPILER_RT=ON \
      -DLIBCXX_INSTALL_HEADERS=ON \
      -DLIBCXX_ENABLE_EXCEPTIONS=ON \
      -DLIBCXX_ENABLE_THREADS=ON \
      -DLIBCXX_HAS_WIN32_THREAD_API=ON \
      -DLIBCXX_ENABLE_MONOTONIC_CLOCK=ON \
      -DLIBCXX_ENABLE_SHARED=OFF \
      -DLIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG=TRUE \
      -DLIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB=TRUE \
      -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \
      -DLIBCXX_ENABLE_FILESYSTEM=OFF \
      -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE \
      -DLIBCXX_CXX_ABI=libcxxabi \
      -DLIBCXX_CXX_ABI_INCLUDE_PATHS=$builddir/clang-source/libcxxabi/include \
      -DLIBCXX_CXX_ABI_LIBRARY_PATH=$builddir/clang-source/libcxxabi/build/lib \
      -DCMAKE_CXX_FLAGS="-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" \
      $builddir/clang-source/libcxx
make -j[% c("num_procs") %] VERBOSE=1
make -j[% c("num_procs") %] install

# libc++.a depends on libunwind.a. While the linker will automatically link to
# libc++.a in C++ mode, it won't pick libunwind.a, requiring the caller to
# explicitly pass -lunwind. To work around that, we merge libunwind.a into
# libc++.a.
merge_libs() {
  cat <<EOF |llvm-ar -M
CREATE tmp.a
ADDLIB $1
ADDLIB $2
SAVE
END
EOF
  llvm-ranlib tmp.a
  mv tmp.a $1
}

merge_libs $distdir/[% c("arch") %]-w64-mingw32/lib/libc++.a $distdir/[% c("arch") %]-w64-mingw32/lib/libunwind.a

# Packaging up everything
cd $distdir
cd ..
[% c('tar', {
        tar_src => [ project ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
    }) %]


code:
# vim: filetype=yaml sw=2
filename: '[% project %]-[% c("version") %]-[% c("var/build_id") %].tar.gz'
git_url: https://git.code.sf.net/p/mingw-w64/mingw-w64
git_hash: cdb052f1d4056cd510cb83197b55868427b87476
version: '[% c("abbrev") %]'
container:
  use_container: 1

var:
  setup: |
    mkdir -p /var/tmp/dist
    tar -C /var/tmp/dist -xf $rootdir/[% c("compiler_tarfile") %]
    export PATH="/var/tmp/dist/mingw-w64-clang/bin:$PATH"

input_files:
  - project: container-image
  - project: clang
    name: clang
  - project: cmake
    name: cmake
  - project: llvm-project
    name: llvm-project
  - project: llvm-mingw
    name: llvm-mingw
  - filename: mingw-winrt.patch
  - filename: mingw-dwrite_3.patch
  - filename: mingw-unknown.patch


code:
From 86f4e9cbb5d3099179dc51332970d61d394116f6 Mon Sep 17 00:00:00 2001
From: Sanketh Menda <me@snkth.com>
Date: Sat, 17 Oct 2020 15:39:42 -0400
Subject: [PATCH] dwrite_3.h: rename GetGlyphImageFormats_ to
 GetGlyphImageFormats

Wine's WIDL currently doesn't support overloading functions, so till
that is fixed patch dwrite_3.h to rename GlyphImageFormats_ to
GetGlyphImageFormats.
---
 mingw-w64-headers/include/dwrite_3.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/mingw-w64-headers/include/dwrite_3.h b/mingw-w64-headers/include/dwrite_3.h
index 427c39e3b..dd894a8b1 100644
--- a/mingw-w64-headers/include/dwrite_3.h
+++ b/mingw-w64-headers/include/dwrite_3.h
@@ -8168,7 +8168,7 @@ DEFINE_GUID(IID_IDWriteFontFace4, 0x27f2a904, 0x4eb8, 0x441d, 0x96,0x78, 0x05,0x
 MIDL_INTERFACE("27f2a904-4eb8-441d-9678-0563f53e3e2f")
 IDWriteFontFace4 : public IDWriteFontFace3
 {
-    virtual HRESULT STDMETHODCALLTYPE GetGlyphImageFormats_(
+    virtual HRESULT STDMETHODCALLTYPE GetGlyphImageFormats(
         UINT16 glyph,
         UINT32 ppem_first,
         UINT32 ppem_last,
@@ -8468,7 +8468,7 @@ typedef struct IDWriteFontFace4Vtbl {
         WINBOOL *are_local);

     /*** IDWriteFontFace4 methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetGlyphImageFormats_)(
+    HRESULT (STDMETHODCALLTYPE *GetGlyphImageFormats)(
         IDWriteFontFace4 *This,
         UINT16 glyph,
         UINT32 ppem_first,
@@ -8549,7 +8549,7 @@ interface IDWriteFontFace4 {
 #define IDWriteFontFace4_AreCharactersLocal(This,characters,count,enqueue_if_not,are_local) (This)->lpVtbl->AreCharactersLocal(This,characters,count,enqueue_if_not,are_local)
 #define IDWriteFontFace4_AreGlyphsLocal(This,glyphs,count,enqueue_if_not,are_local) (This)->lpVtbl->AreGlyphsLocal(This,glyphs,count,enqueue_if_not,are_local)
 /*** IDWriteFontFace4 methods ***/
-#define IDWriteFontFace4_GetGlyphImageFormats_(This,glyph,ppem_first,ppem_last,formats) (This)->lpVtbl->GetGlyphImageFormats_(This,glyph,ppem_first,ppem_last,formats)
+#define IDWriteFontFace4_GetGlyphImageFormats(This,glyph,ppem_first,ppem_last,formats) (This)->lpVtbl->GetGlyphImageFormats(This,glyph,ppem_first,ppem_last,formats)
 #define IDWriteFontFace4_GetGlyphImageFormats(This) (This)->lpVtbl->GetGlyphImageFormats(This)
 #define IDWriteFontFace4_GetGlyphImageData(This,glyph,ppem,format,data,context) (This)->lpVtbl->GetGlyphImageData(This,glyph,ppem,format,data,context)
 #define IDWriteFontFace4_ReleaseGlyphImageData(This,context) (This)->lpVtbl->ReleaseGlyphImageData(This,context)
@@ -8692,8 +8692,8 @@ static FORCEINLINE HRESULT IDWriteFontFace4_AreGlyphsLocal(IDWriteFontFace4* Thi
     return This->lpVtbl->AreGlyphsLocal(This,glyphs,count,enqueue_if_not,are_local);
 }
 /*** IDWriteFontFace4 methods ***/
-static FORCEINLINE HRESULT IDWriteFontFace4_GetGlyphImageFormats_(IDWriteFontFace4* This,UINT16 glyph,UINT32 ppem_first,UINT32 ppem_last,DWRITE_GLYPH_IMAGE_FORMATS *formats) {
-    return This->lpVtbl->GetGlyphImageFormats_(This,glyph,ppem_first,ppem_last,formats);
+static FORCEINLINE HRESULT IDWriteFontFace4_GetGlyphImageFormats(IDWriteFontFace4* This,UINT16 glyph,UINT32 ppem_first,UINT32 ppem_last,DWRITE_GLYPH_IMAGE_FORMATS *formats) {
+    return This->lpVtbl->GetGlyphImageFormats(This,glyph,ppem_first,ppem_last,formats);
 }
 static FORCEINLINE DWRITE_GLYPH_IMAGE_FORMATS IDWriteFontFace4_GetGlyphImageFormats(IDWriteFontFace4* This) {
     return This->lpVtbl->GetGlyphImageFormats(This);
@@ -9020,7 +9020,7 @@ typedef struct IDWriteFontFace5Vtbl {
         WINBOOL *are_local);

     /*** IDWriteFontFace4 methods ***/
-    HRESULT (STDMETHODCALLTYPE *GetGlyphImageFormats_)(
+    HRESULT (STDMETHODCALLTYPE *GetGlyphImageFormats)(
         IDWriteFontFace5 *This,
         UINT16 glyph,
         UINT32 ppem_first,
@@ -9121,7 +9121,7 @@ interface IDWriteFontFace5 {
 #define IDWriteFontFace5_AreCharactersLocal(This,characters,count,enqueue_if_not,are_local) (This)->lpVtbl->AreCharactersLocal(This,characters,count,enqueue_if_not,are_local)
 #define IDWriteFontFace5_AreGlyphsLocal(This,glyphs,count,enqueue_if_not,are_local) (This)->lpVtbl->AreGlyphsLocal(This,glyphs,count,enqueue_if_not,are_local)
 /*** IDWriteFontFace4 methods ***/
-#define IDWriteFontFace5_GetGlyphImageFormats_(This,glyph,ppem_first,ppem_last,formats) (This)->lpVtbl->GetGlyphImageFormats_(This,glyph,ppem_first,ppem_last,formats)
+#define IDWriteFontFace5_GetGlyphImageFormats(This,glyph,ppem_first,ppem_last,formats) (This)->lpVtbl->GetGlyphImageFormats(This,glyph,ppem_first,ppem_last,formats)
 #define IDWriteFontFace5_GetGlyphImageFormats(This) (This)->lpVtbl->GetGlyphImageFormats(This)
 #define IDWriteFontFace5_GetGlyphImageData(This,glyph,ppem,format,data,context) (This)->lpVtbl->GetGlyphImageData(This,glyph,ppem,format,data,context)
 #define IDWriteFontFace5_ReleaseGlyphImageData(This,context) (This)->lpVtbl->ReleaseGlyphImageData(This,context)
@@ -9270,8 +9270,8 @@ static FORCEINLINE HRESULT IDWriteFontFace5_AreGlyphsLocal(IDWriteFontFace5* Thi
     return This->lpVtbl->AreGlyphsLocal(This,glyphs,count,enqueue_if_not,are_local);
 }
 /*** IDWriteFontFace4 methods ***/
-static FORCEINLINE HRESULT IDWriteFontFace5_GetGlyphImageFormats_(IDWriteFontFace5* This,UINT16 glyph,UINT32 ppem_first,UINT32 ppem_last,DWRITE_GLYPH_IMAGE_FORMATS *formats) {
-    return This->lpVtbl->GetGlyphImageFormats_(This,glyph,ppem_first,ppem_last,formats);
+static FORCEINLINE HRESULT IDWriteFontFace5_GetGlyphImageFormats(IDWriteFontFace5* This,UINT16 glyph,UINT32 ppem_first,UINT32 ppem_last,DWRITE_GLYPH_IMAGE_FORMATS *formats) {
+    return This->lpVtbl->GetGlyphImageFormats(This,glyph,ppem_first,ppem_last,formats);
 }
 static FORCEINLINE DWRITE_GLYPH_IMAGE_FORMATS IDWriteFontFace5_GetGlyphImageFormats(IDWriteFontFace5* This) {
     return This->lpVtbl->GetGlyphImageFormats(This);


code:
From ae5fe7a557873f05a4954f4b3a47e4b41053a406 Mon Sep 17 00:00:00 2001
From: Tom Ritter <tom@ritter.vg>
Date: Tue, 29 Jun 2021 23:10:24 -0400
Subject: [PATCH] Add back the IUnknown_QI functions

---
 mingw-w64-headers/include/unknwn.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/mingw-w64-headers/include/unknwn.h b/mingw-w64-headers/include/unknwn.h
index d8c309071..968c41d61 100644
--- a/mingw-w64-headers/include/unknwn.h
+++ b/mingw-w64-headers/include/unknwn.h
@@ -167,6 +167,29 @@ static FORCEINLINE ULONG IUnknown_Release(IUnknown* This) {

 #endif

+HRESULT STDMETHODCALLTYPE IUnknown_QueryInterface_Proxy(
+    IUnknown* This,
+    REFIID riid,
+    void **ppvObject);
+void __RPC_STUB IUnknown_QueryInterface_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+ULONG STDMETHODCALLTYPE IUnknown_AddRef_Proxy(
+    IUnknown* This);
+void __RPC_STUB IUnknown_AddRef_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+ULONG STDMETHODCALLTYPE IUnknown_Release_Proxy(
+    IUnknown* This);
+void __RPC_STUB IUnknown_Release_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);

 #endif  /* __IUnknown_INTERFACE_DEFINED__ */

--
2.25.1