Skip to content

Instantly share code, notes, and snippets.

@mid-kid
Last active November 21, 2021 17:17
Show Gist options
  • Save mid-kid/e1b472bafa6bf74d235ec3a9d2b6bcc0 to your computer and use it in GitHub Desktop.
Save mid-kid/e1b472bafa6bf74d235ec3a9d2b6bcc0 to your computer and use it in GitHub Desktop.
Generate a tarball from dotnet/source-build
#!/bin/sh
set -e
# Script to generate a semi-reproducible dotnet source tarball
# The only differences accross builds are in the git-info/ directory,
# the OfficialBuildId being generated based on the current date.
# See tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/WriteSourceRepoProperties.cs
version="v${1:-5.0.209.1}-SDK"
if [ ! -d source-build ]; then
git clone --depth=1 -b "$version" --recursive https://github.com/dotnet/source-build
fi
cd source-build
# Required when clang is built with -DCLANG_DEFAULT_LINKER=lld
# See https://github.com/dotnet/runtime/pull/45664
cat > clang-bfd << 'EOF'
#!/bin/sh
exec clang -fuse-ld=bfd -Wno-unused-command-line-argument "$@"
EOF
cat > clang++-bfd << 'EOF'
#!/bin/sh
exec clang++ -fuse-ld=bfd -Wno-unused-command-line-argument "$@"
EOF
chmod +x clang-bfd clang++-bfd
PATH="$PWD/.dotnet:$PATH" \
CLR_CC="$PWD/clang-bfd" \
CLR_CXX="$PWD/clang++-bfd" \
./build-source-tarball.sh "dotnet-$version" --base-tarball
# Make sure the artifacts/obj/<arch> directory is x64, regardless of the
# architecture currently being used.
mv -T "dotnet-$version"/artifacts/obj/*/ "dotnet-$version"/artifacts/obj/x64 || true
# Using mtime=1990 because zip can't store dates prior to 1980,
# making the build error out.
tar --format=gnu --sort=name --owner=0 --group=0 --numeric-owner \
--mtime='1990-01-01Z' \
-cvf "dotnet-$version.tar" "dotnet-$version"
xz -9v "dotnet-$version.tar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment