Skip to content

Commit

Permalink
test: test out cross compilation of dotnet app to executable
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed May 17, 2024
1 parent 5202bca commit 06453de
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/build-test-cross.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: cross compile dotnet app
on:
push:
branches:
- "**"
pull_request:
branches:
- "**"

jobs:
build:
runs-on: macos-14
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.x
- name: build dotnet executables
run: make build
- name: size of executables
run: make size
- name: file info
run: make file
- uses: actions/upload-artifact@v4
with:
path: bin/*

test:
defaults:
run:
shell: sh
needs: [build]
strategy:
fail-fast: false
matrix:
os: ["macos-14"]
runs-on: ${{ matrix.os }}
steps:
- name: Download all workflow run artifacts
uses: actions/download-artifact@v3
- name: list bin
run: ls bin/*
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
all: build

APP_NAME = "hello_dotnet"

RIDS = "linux-x64" "linux-arm64" "linux-musl-x64" "linux-musl-arm64" "osx-x64" "osx-arm64" "win-x64" "win-arm64"

build: clean
for rid in $(RIDS); do \
echo "Building for $$rid..."; \
dotnet publish -c Release -p:PublishSingleFile=true -p:SelfContained=true -p:PublishReadyToRun=true -p:PublishTrimmed=true -p:StaticLink=true -r $$rid -o bin/$(APP_NAME)-$$rid; \
done || true

# the above true condition is a yak shave,
# /usr/local/share/dotnet/sdk/7.0.409/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(111,5):
# error NETSDK1098: Applications published to a single-file are required to use the application host.
# You must either set PublishSingleFile to false or set UseAppHost to true.

debug: clean
@echo "Building in debug mode..."
for rid in $(RIDS); do \
echo "Building for $$rid..."; \
dotnet publish -c Debug -p:PublishSingleFile=true -p:SelfContained=true -p:PublishReadyToRun=true-r $$rid -o bin/$(APP_NAME)-$$rid; \
done

size:
@echo "Size of the binaries:"
for rid in $(RIDS); do \
echo "Size of bin/$(APP_NAME)-$$rid:"; \
ls -lh bin/$(APP_NAME)-$$rid/; \
done

file:
@echo "File type of the binaries:"
for rid in $(RIDS); do \
echo "File type of bin/$(APP_NAME)-$$rid:"; \
file bin/$(APP_NAME)-$$rid/*; \
done

clean:
@echo "Cleaning..."
@rm -rf bin
@rm -rf obj
2 changes: 2 additions & 0 deletions src/Explore.Cli/Explore.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<PackageReference Include="NJsonSchema" Version="10.9.0" />
<PackageReference Include="Spectre.Console" Version="0.47.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.Text.Encoding.Extensions" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 06453de

Please sign in to comment.