Skip to content

Commit

Permalink
feat: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
trungnt2910 committed Jun 3, 2023
0 parents commit e63e084
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: trungnt2910
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: trungnt2910
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
178 changes: 178 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
repository_dispatch:
types: [webhook]
push:
paths-ignore:
- README.md
branches:
- master

permissions:
contents: write
packages: write

env:
ROOTFS_DIR: ${{ github.workspace }}/dotnet-rootfs
DOTNET_MAJOR_VERSION: 8
DOTNET_ARCH: x64
DOTNET_OS: haiku
CONFIGURATION: Debug

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install build dependencies
run: sudo apt install -y liblttng-ust-dev

# See https://github.com/actions/virtual-environments/issues/2606#issuecomment-772683150
- name: Chuck out the trash
run: |
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
- name: Determine build ID
id: buildid
run: |
latestRev=""
today=$(date --utc +%Y%m%d)
releaseUrl="${{ github.server_url }}/${{ github.repository }}/releases/tag/net${{ env.DOTNET_MAJOR_VERSION }}-${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}-$today."
pageNum=1
while [ -z "$latestRev" ];
do
json=$(curl -s ${{ github.api_url }}/repos/${{ github.repository }}/releases?page=$pageNum)
pageNum=$((pageNum + 1))
if [ $(echo $json | jq length) -eq 0 ]; then
# This means that we've passed the end and reached an empty array
break
fi
if [ $(echo $json | jq 'objects // {} | has("message")') == "true" ]; then
# API has return an error object
echo "Unable to fetch releases from GitHub API"
exit 2
fi
# Store array of revisions
revisions=($(echo $json | jq -e -r ".[] | .html_url | select(true)[${#releaseUrl}:]")) \
|| continue
latestRev=${revisions[0]}
done
if [ -z "$latestRev" ]; then
latestRev=0
fi
latestRev=$((latestRev + 1))
echo buildid=$today.$latestRev >> "$GITHUB_OUTPUT"
- name: Clone .NET Runtime
run: git clone https://github.com/trungnt2910/dotnet-runtime -b haiku-dotnet${{ env.DOTNET_MAJOR_VERSION }} --depth=1 ${{ github.workspace }}/runtime

- name: Build rootfs
run: ${{ github.workspace }}/runtime/eng/common/cross/build-rootfs.sh ${{ env.DOTNET_ARCH }} ${{ env.DOTNET_OS }}

- name: Build .NET Runtime
run: ${{ github.workspace }}/runtime/build.sh --ci -c ${{ env.CONFIGURATION }} -arch ${{ env.DOTNET_ARCH }} -os ${{ env.DOTNET_OS }} -cross -gcc /p:OfficialBuildId=${{ steps.buildid.outputs.buildid }}

- name: Determine .NET version
id: version
run: |
shopt -s extglob
echo version=$(sed -r 's/(.*Microsoft\.NETCore\.App\.Ref\.)(.*?)(\.nupkg)/\2/' <<< $(ls ${{ github.workspace }}/runtime/artifacts/packages/Debug/Shipping/Microsoft.NETCore.App.Ref.!(*symbols).nupkg)) >> "$GITHUB_OUTPUT"
- name: Extract tarballs
run: |
shopt -s extglob
mkdir ${{ github.workspace }}/output
pushd ${{ github.workspace }}/output
for f in ${{ github.workspace }}/runtime/artifacts/packages/${{ env.CONFIGURATION }}/Shipping/!(*symbols*).tar.gz; do tar xf "$f"; done
popd
- name: Clone .NET SDK
run: git clone https://github.com/trungnt2910/dotnet-sdk -b haiku-dotnet${{ env.DOTNET_MAJOR_VERSION }} --depth=1 ${{ github.workspace }}/sdk

- name: Build .NET SDK
run: |
${{ github.workspace }}/sdk/build.sh --ci --pack -c ${{ env.CONFIGURATION }} /p:OSName=${{ env.DOTNET_OS }} /p:Architecture=${{ env.DOTNET_ARCH }} /p:OfficialBuildId=${{ steps.buildid.outputs.buildid }}
dotnetVersion=${{ steps.version.outputs.version }}
sdkFeatureBand=$(ls ${{ github.workspace }}/sdk/artifacts/bin/redist/${{ env.CONFIGURATION }}/dotnet/sdk)
pushd ${{ github.workspace }}/sdk/artifacts/bin/redist/${{ env.CONFIGURATION }}/dotnet/sdk/$sdkFeatureBand
# Update RuntimeIdentifierGraph
cp -f ${{ github.workspace }}/runtime/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json ./RuntimeIdentifierGraph.json
# Patch SDK properties, framework reference pack, and app host pack
# PLEASE DO NOT ASK ME WHAT THESE SED COMMANDS MEAN!
sed -ri "s/<BundledNETCoreAppPackageVersion>.*<\/BundledNETCoreAppPackageVersion>/<BundledNETCoreAppPackageVersion>$dotnetVersion<\/BundledNETCoreAppPackageVersion>/" ./Microsoft.NETCoreSdk.BundledVersions.props
sed -ri "s/<BundledNETCorePlatformsPackageVersion>.*<\/BundledNETCorePlatformsPackageVersion>/<BundledNETCorePlatformsPackageVersion>$dotnetVersion<\/BundledNETCorePlatformsPackageVersion>/" ./Microsoft.NETCoreSdk.BundledVersions.props
sed -ri "s/<NETCoreSdkRuntimeIdentifier>.*<\/NETCoreSdkRuntimeIdentifier>/<NETCoreSdkRuntimeIdentifier>${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}<\/NETCoreSdkRuntimeIdentifier>/" ./Microsoft.NETCoreSdk.BundledVersions.props
sed -ri "s/<NETCoreSdkPortableRuntimeIdentifier>.*<\/NETCoreSdkPortableRuntimeIdentifier>/<NETCoreSdkPortableRuntimeIdentifier>${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}<\/NETCoreSdkPortableRuntimeIdentifier>/" ./Microsoft.NETCoreSdk.BundledVersions.props
sed -ri "s/(<KnownFrameworkReference.* DefaultRuntimeFrameworkVersion=\")${{ env.DOTNET_MAJOR_VERSION }}[^\"]*(\".* \/>)/\1$dotnetVersion\2/" ./Microsoft.NETCoreSdk.BundledVersions.props
sed -ri "s/(<KnownFrameworkReference.* LatestRuntimeFrameworkVersion=\")${{ env.DOTNET_MAJOR_VERSION }}[^\"]*(\".* \/>)/\1$dotnetVersion\2/" ./Microsoft.NETCoreSdk.BundledVersions.props
sed -ri "s/(<KnownFrameworkReference.* TargetingPackVersion=\")${{ env.DOTNET_MAJOR_VERSION }}[^\"]*(\".* \/>)/\1$dotnetVersion\2/" ./Microsoft.NETCoreSdk.BundledVersions.props
sed -ri "s/(<KnownFrameworkReference.* DefaultRuntimeFrameworkVersion=\"$dotnetVersion\".*RuntimePackRuntimeIdentifiers=\")([^\"]*)(\".* \/>)/\1\2;${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}\3/" ./Microsoft.NETCoreSdk.BundledVersions.props
sed -ri "s/(<KnownAppHostPack.* AppHostPackVersion=\")${{ env.DOTNET_MAJOR_VERSION }}[^\"]*(\".* \/>)/\1$dotnetVersion\2/" ./Microsoft.NETCoreSdk.BundledVersions.props
sed -ri "s/(<KnownAppHostPack.* AppHostPackVersion=\"$dotnetVersion\".*AppHostRuntimeIdentifiers=\")([^\"]*)(\".* \/>)/\1\2;${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}\3/" ./Microsoft.NETCoreSdk.BundledVersions.props
# Other packs (at the time of writing, crossgen2 and ilcompiler) are not supported on Haiku
popd
- name: Copy .NET SDK
run: |
shopt -s extglob
# SDK
cp -r ${{ github.workspace }}/sdk/artifacts/bin/redist/${{ env.CONFIGURATION }}/dotnet/sdk ${{ github.workspace }}/output
# Templates
dotnetVersion=${{ steps.version.outputs.version }}
mkdir -p ${{ github.workspace }}/output/templates/$dotnetVersion
cp ${{ github.workspace }}/sdk/artifacts/packages/Debug/Shipping/*Templates!(*symbols*).nupkg ${{ github.workspace }}/output/templates/$dotnetVersion
- name: Create .NET tarball
run: |
pushd ${{ github.workspace }}/output
fileName=${{ github.workspace }}/net${{ env.DOTNET_MAJOR_VERSION }}-${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}-${{ steps.buildid.outputs.buildid }}
tar -cf $fileName.tar *
gzip -9 < $fileName.tar > $fileName.tar.gz
popd
- name: Upload .NET artifact
uses: actions/upload-artifact@v3
with:
name: net${{ env.DOTNET_MAJOR_VERSION }}-${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}-${{ steps.buildid.outputs.buildid }}.tar
path: ${{ github.workspace }}/net${{ env.DOTNET_MAJOR_VERSION }}-${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}-${{ steps.buildid.outputs.buildid }}.tar

- name: Upload .NET NuGet packages artifact
uses: actions/upload-artifact@v3
with:
name: dotnet-nuget
path: ${{ github.workspace }}/runtime/artifacts/packages/${{ env.CONFIGURATION }}/Shipping/*.nupkg

- name: Create release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: net${{ env.DOTNET_MAJOR_VERSION }}-${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}-${{ steps.buildid.outputs.buildid }}
prerelease: false
title: .NET ${{ env.DOTNET_MAJOR_VERSION }} for Haiku ${{ env.DOTNET_ARCH }} build ${{ steps.buildid.outputs.buildid }}
files: |
${{ github.workspace }}/runtime/artifacts/packages/${{ env.CONFIGURATION }}/Shipping/*
${{ github.workspace }}/sdk/artifacts/packages/${{ env.CONFIGURATION }}/Shipping/*
${{ github.workspace }}/net${{ env.DOTNET_MAJOR_VERSION }}-${{ env.DOTNET_OS }}-${{ env.DOTNET_ARCH }}-${{ steps.buildid.outputs.buildid }}.tar.gz
- name: Publish NuGet packages on GitHub
run: |
shopt -s extglob
dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
# Do not upload symbol packages because:
# - No debugging support on Haiku yet.
# - Pushing symbols packages to GitHub Packages seems to fail with 403 Forbidden.
dotnet nuget push ${{ github.workspace }}/runtime/artifacts/packages/${{ env.CONFIGURATION }}/Shipping/!(*symbols*).nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "github"
dotnet nuget push ${{ github.workspace }}/sdk/artifacts/packages/${{ env.CONFIGURATION }}/Shipping/!(*symbols*).nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "github"
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# dotnet-builds

.NET binary builds for Haiku.

## What's included

At the time of writing, this repo currently builds a preview release of .NET 8.

- [dotnet/runtime](https://github.com/trungnt2910/dotnet-runtime): .NET Runtime, ported to Haiku.
- [dotnet/sdk](https://github.com/trungnt2910/dotnet-sdk): .NET SDK, ported to Haiku.

Other components, notably ASP.NET and NativeAOT are not supported yet.

## Installation

- Download a copy of `net8-haiku-x64-<randomly seeming build number>.tar.gz` from the latest [release](https://github.com/trungnt2910/dotnet-builds/releases/latest).
- Install dependencies:
```sh
pkgman install -y gmp krb5 libiconv llvm12_libunwind mpfr
```
- Extract the archive to any folder and add it to the system's `$PATH`.
- Add some hack environment variables mentioned [here](https://discuss.haiku-os.org/t/gsoc-2023-net-port/13237/39) to the `dotnet` binary:
```sh
addattr SYS:ENV "DOTNET_SYSTEM_NET_DISABLEIPV6=1\\0COMPlus_EnableWriteXorExecute=0" /path/to/where/you/extract/the/zip/file/dotnet
```
- Add a custom NuGet source containing essential Haiku-specific packages. `your_github_token` should be a [personal access token](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry#authenticating-to-github-packages) with at least the `read:packages` permission:
```sh
dotnet nuget add source --username your_github_username --password your_github_token --store-password-in-clear-text --name dotnet_haiku_nuget "https://nuget.pkg.github.com/trungnt2910/index.json"
```
- Now you can carry out the basic steps to create a "Hello, World!" application:
```sh
mkdir helloworld
cd helloworld
dotnet new console
dotnet run
```

## Build frequency

This repository will be built:
- At the start of every week to keep track of Haiku updates.
- Whenever the default branch (currently `haiku-dotnet8`) of any of the repositories mentioned above is pushed.
- Whenever the default branch (`master`) of this repository is pushed.
- Whenever [@trungnt2910](https://github.com/trungnt2910) wants to create a new release.

## FAQs

### Why do I need a GitHub token to install public packages?

For some weird reasons, GitHub NuGet feeds [require](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry#authenticating-to-github-packages) authentication, even for public packages.

### Why are the packages published on GitHub instead of NuGet?

The packages involved cannot be published on [nuget.org](https://nuget.org) because their names start with `Microsoft.`, and that prefix is [reserved](https://learn.microsoft.com/en-us/nuget/nuget-org/id-prefix-reservation). If there are any better free NuGet package hosting options, please let me know by opening an issue.

### Why are you telling me to store my password in clear text?

This is not a malicious attempt to expose your GitHub token, but a technical limitation by .NET:

```
error: Password encryption is not supported on .NET Core for this platform. The following feed try to use an encrypted password: 'dotnet_haiku_nuget'. You can use a clear text password as a workaround.
error: Encryption is not supported on non-Windows platforms.
```

### Will there be a HaikuPorts recipe and `.hpkg` packages?

Not in the near future, because:
- The current branch is using a prerelease version of .NET 8.
- Many PRs are waiting to get merged upstream.
- No official documentation (at least, not among the ones I know) on how to create packages that have themselves as a build prerequisite.
- Unconventional installation layout. All of .NET lives in one directory, and it should be writable so that additional workloads or other optional components can be installed through NuGet, instead of being divided into `/bin`, `/lib`, etc. like other UNIX applications.

More discussion can be found in [this](https://discuss.haiku-os.org/t/gsoc-2023-net-port/13237/44) forum comment and the following ones.

### Why is this build so slow?

This build of .NET is a **Debug** build. Release builds are currently not provided because of some weird bugs like [this one](https://github.com/dotnet/runtime/issues/55803#issuecomment-1547175040).

## License

.NET binary releases and artifacts belong to the .NET Foundation and Contributors, and are covered by the [MIT License](https://github.com/dotnet/runtime/blob/main/LICENSE.TXT).

Scripts and documentation in this repository (C) 2023 Trung Nguyen. All rights reserved.

0 comments on commit e63e084

Please sign in to comment.