Skip to content

Commit facead9

Browse files
author
Timmy Silesmo
committed
C# MacOS support
1 parent ffbf78c commit facead9

File tree

3 files changed

+82
-11
lines changed

3 files changed

+82
-11
lines changed

.github/workflows/main.yml

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ jobs:
8080
os: [ubuntu-latest, macos-latest, windows-latest]
8181
# moonbit removed from language matrix for now - causing CI failures
8282
lang: [c, rust, csharp, cpp, go]
83-
exclude:
84-
# For now csharp doesn't work on macos, so exclude it from testing.
85-
- os: macos-latest
86-
lang: csharp
8783
runs-on: ${{ matrix.os }}
84+
env:
85+
RUNTIMELAB_COMMIT: '4cac3ab5c8e97fda69c23dfca41ace964babc05e'
8886
steps:
8987
- uses: actions/checkout@v4
9088
with:
@@ -103,7 +101,14 @@ jobs:
103101
uses: actions/setup-dotnet@v4
104102
with:
105103
dotnet-version: '9.x'
106-
if: matrix.lang == 'csharp'
104+
if: matrix.lang == 'csharp' && runner.os != 'macOS'
105+
106+
- name: Setup .NET 10 (macOS)
107+
uses: actions/setup-dotnet@v4
108+
with:
109+
dotnet-version: '10.x'
110+
dotnet-quality: 'preview'
111+
if: matrix.lang == 'csharp' && runner.os == 'macOS'
107112

108113
- name: Setup Go
109114
uses: actions/setup-go@v5
@@ -125,6 +130,55 @@ jobs:
125130
shell: powershell
126131
if: matrix.os == 'windows-latest' && matrix.lang == 'moonbit'
127132
133+
# macOS C# requires locally-built ILC packages since no osx-arm64
134+
# packages are published on NuGet.
135+
- name: Cache runtimelab ILC packages
136+
id: cache-runtimelab
137+
uses: actions/cache@v4
138+
with:
139+
path: runtimelab-packages
140+
key: runtimelab-macos-arm64-${{ env.RUNTIMELAB_COMMIT }}
141+
if: runner.os == 'macOS' && matrix.lang == 'csharp'
142+
143+
- name: Install LLVM 18 for runtimelab build
144+
if: runner.os == 'macOS' && matrix.lang == 'csharp' && steps.cache-runtimelab.outputs.cache-hit != 'true'
145+
run: brew install llvm@18
146+
147+
- name: Checkout runtimelab
148+
uses: actions/checkout@v4
149+
with:
150+
repository: dotnet/runtimelab
151+
ref: ${{ env.RUNTIMELAB_COMMIT }}
152+
path: runtimelab
153+
if: runner.os == 'macOS' && matrix.lang == 'csharp' && steps.cache-runtimelab.outputs.cache-hit != 'true'
154+
155+
- name: Build runtimelab ILC packages
156+
if: runner.os == 'macOS' && matrix.lang == 'csharp' && steps.cache-runtimelab.outputs.cache-hit != 'true'
157+
run: |
158+
cd runtimelab
159+
ln -sf $WASI_SDK_PATH src/mono/wasi/wasi-sdk
160+
mkdir -p src/mono/wasi/include
161+
162+
# Build wasi libs and packages
163+
./build.sh clr.aot+libs -c Release -a wasm -os wasi /p:NuGetAudit=false
164+
./build.sh nativeaot.packages -c Release -a wasm -os wasi /p:NuGetAudit=false
165+
166+
# Build host compiler, libs, WASM JIT, and packages
167+
./build.sh clr.aot -c Release /p:NuGetAudit=false
168+
./build.sh libs -c Release /p:NuGetAudit=false
169+
LLVM_CMAKE_CONFIG_RELEASE=$(brew --prefix llvm@18)/lib/cmake/llvm \
170+
src/coreclr/build-runtime.sh -arm64 -release -os osx -outputrid osx-arm64 -component wasmjit
171+
./build.sh nativeaot.packages -c Release /p:NuGetAudit=false
172+
173+
mkdir -p ../runtimelab-packages
174+
cp artifacts/packages/Release/Shipping/*.nupkg ../runtimelab-packages/
175+
176+
- name: Set ILC env vars for macOS C#
177+
if: runner.os == 'macOS' && matrix.lang == 'csharp'
178+
run: |
179+
echo "ILC_VERSION=10.0.0-dev" >> $GITHUB_ENV
180+
echo "ILC_PACKAGES_PATH=${{ github.workspace }}/runtimelab-packages" >> $GITHUB_ENV
181+
128182
# Run all codegen tests for this language
129183
- run: |
130184
cargo run test --languages ${{ matrix.lang }} tests/codegen \

crates/csharp/src/csproj.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::Result;
2-
use std::{fs, path::PathBuf};
2+
use std::{env, fs, path::PathBuf};
33

44
use heck::ToUpperCamelCase;
55

@@ -103,21 +103,36 @@ impl CSProjectLLVMBuilder {
103103
let os = match std::env::consts::OS {
104104
"windows" => "win",
105105
"linux" => std::env::consts::OS,
106+
"macos" => "osx",
106107
other => todo!("OS {} not supported", other),
107108
};
108109

110+
let arch = match std::env::consts::ARCH {
111+
"aarch64" => "arm64",
112+
"x86_64" => "x64",
113+
other => todo!("ARCH {} not supported", other),
114+
};
115+
116+
let ilc_version = env::var("ILC_VERSION").unwrap_or_else(|_| "10.0.0-*".to_string());
117+
109118
csproj.push_str(
110119
&format!(
111120
r#"
112121
<ItemGroup>
113-
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="10.0.0-*" />
114-
<PackageReference Include="runtime.{os}-x64.Microsoft.DotNet.ILCompiler.LLVM" Version="10.0.0-*" />
122+
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="{ilc_version}" />
123+
<PackageReference Include="runtime.{os}-{arch}.Microsoft.DotNet.ILCompiler.LLVM" Version="{ilc_version}" />
115124
</ItemGroup>"#),
116125
);
117126

127+
let local_source = match env::var("ILC_PACKAGES_PATH") {
128+
Ok(path) => format!(r#"<add key="local-ilc" value="{path}" />"#),
129+
Err(_) => String::new(),
130+
};
131+
118132
fs::write(
119133
self.dir.join("nuget.config"),
120-
r#"<?xml version="1.0" encoding="utf-8"?>
134+
format!(
135+
r#"<?xml version="1.0" encoding="utf-8"?>
121136
<configuration>
122137
<config>
123138
<!-- Store the packages where they can be shared between tests -->
@@ -126,11 +141,12 @@ impl CSProjectLLVMBuilder {
126141
<packageSources>
127142
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
128143
<clear />
144+
{local_source}
129145
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
130146
<add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
131-
<!--<add key="dotnet-experimental" value="C:\github\runtimelab\artifacts\packages\Debug\Shipping" />-->
132147
</packageSources>
133-
</configuration>"#,
148+
</configuration>"#
149+
),
134150
)?;
135151
}
136152

crates/test/src/csharp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ impl LanguageMethods for Csharp {
9999
let os = match std::env::consts::OS {
100100
"windows" => "win",
101101
"linux" => std::env::consts::OS,
102+
"macos" => "osx",
102103
other => todo!("OS {} not supported", other),
103104
};
104105

0 commit comments

Comments
 (0)