Skip to content

Commit 912b9fc

Browse files
committed
Added support for building Linux binaries on CI. Added Linux binary to ClangSharp.Pathogen.Runtime.
Fixes MochiLibraries#1
1 parent fe61ccd commit 912b9fc

File tree

3 files changed

+73
-18
lines changed

3 files changed

+73
-18
lines changed

.github/workflows/ClangSharp.Pathogen.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,24 @@ env:
2020
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
2121
jobs:
2222
build-llvm:
23-
name: Build LLVM
24-
runs-on: windows-latest
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
include:
27+
- os: windows-latest
28+
name: Windows
29+
lib-path: build/bin/libclang.dll
30+
build-command: ./build-native.cmd
31+
artifact-name: LlvmBuildOutputs-Windows
32+
# We use Ubuntu 18.04 so that the binary is usable on systems using glibc 2.27 and later
33+
# If we want to support even older versions we should explore building libclang with https://github.com/wheybags/glibc_version_header
34+
- os: ubuntu-18.04
35+
name: Linux
36+
lib-path: build-linux/lib/libclang.so
37+
build-command: ./build-native.sh
38+
artifact-name: LlvmBuildOutputs-Linux
39+
name: Build LLVM - ${{matrix.name}}
40+
runs-on: ${{matrix.os}}
2541
steps:
2642
# ----------------------------------------------------------------------- Checkout
2743
- name: Checkout
@@ -47,9 +63,8 @@ jobs:
4763
with:
4864
key: llvm-output-${{runner.os}}-${{steps.llvm.outputs.revision}}
4965
# These are the paths of the external files required in ClangSharp.Pathogen.Runtime.csproj
50-
# (Version.props is required by tooling/Versioning.props)
5166
# (Make sure this is syncronized with "Archive LLVM Outputs" below)
52-
path: build/bin/libclang.dll
67+
path: ${{matrix.lib-path}}
5368

5469
- name: Checkout LLVM
5570
if: steps.cached-llvm.outputs.cache-hit != 'true'
@@ -73,21 +88,35 @@ jobs:
7388
if: steps.cached-llvm.outputs.cache-hit != 'true'
7489
run: sccache --start-server
7590

91+
# The GitHub hosted runners do not have Ninja installed by default
92+
# We only need to do this on Linux since Visual Studio comes with a copy of Ninja and we end up picking that one up for Windows
93+
- name: Install Ninja
94+
if: steps.cached-llvm.outputs.cache-hit != 'true' && runner.os == 'Linux'
95+
run: sudo apt install --yes ninja-build
96+
7697
- name: Build LLVM
7798
if: steps.cached-llvm.outputs.cache-hit != 'true'
78-
run: ./build-native.cmd
99+
run: ${{matrix.build-command}}
79100

80101
- name: Show sccache statistics
81102
if: steps.cached-llvm.outputs.cache-hit != 'true'
82103
run: sccache --show-stats
83104

105+
# The GitHub Actions cache gets confused by the symlink so we need to remove it
106+
- name: Unsymlink libclang
107+
if: steps.cached-llvm.outputs.cache-hit != 'true' && runner.os == 'Linux'
108+
run: |
109+
cp ${{matrix.lib-path}} ${{matrix.lib-path}}-nosymlink
110+
rm ${{matrix.lib-path}}
111+
mv ${{matrix.lib-path}}-nosymlink ${{matrix.lib-path}}
112+
84113
- name: Upload LLVM build artifacts
85114
uses: actions/upload-artifact@v2
86115
with:
87-
name: LlvmBuildOutputs
116+
name: ${{matrix.artifact-name}}
88117
if-no-files-found: error
89-
# This paths listed here must match "Load cached LLVM build outputs" above
90-
path: build/bin/libclang.dll
118+
# The paths listed here must match "Load cached LLVM build outputs" above
119+
path: ${{matrix.lib-path}}
91120

92121
build-dotnet:
93122
name: Build ClangSharp.Pathogen
@@ -117,11 +146,16 @@ jobs:
117146
dotnet-version: 5.0.x
118147

119148
# ----------------------------------------------------------------------- Download LLVM Build
120-
- name: Download LLVM build artifacts
149+
- name: Download LLVM Windows build artifacts
121150
uses: actions/download-artifact@v2
122151
with:
123-
name: LlvmBuildOutputs
152+
name: LlvmBuildOutputs-Windows
124153
path: build/bin/
154+
- name: Download LLVM Linux build artifacts
155+
uses: actions/download-artifact@v2
156+
with:
157+
name: LlvmBuildOutputs-Linux
158+
path: build-linux/lib/
125159

126160
# ----------------------------------------------------------------------- Configure versioning
127161
- name: Configure build
@@ -167,6 +201,7 @@ jobs:
167201
with:
168202
name: Packages
169203
path: packages/**
204+
170205
publish-packages:
171206
name: Publish ClangSharp.Pathogen
172207
runs-on: ubuntu-latest

ClangSharp.Pathogen.Runtime/ClangSharp.Pathogen.Runtime.csproj

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
77

88
<!-- Paths to LLVM things -->
9-
<LibClangPathogenPath>$(MSBuildThisFileDirectory)../build/bin/libclang.dll</LibClangPathogenPath>
9+
<LibClangPathogenPathWindows>$(MSBuildThisFileDirectory)../build/bin/libclang.dll</LibClangPathogenPathWindows>
10+
<LibClangPathogenPathLinux>$(MSBuildThisFileDirectory)../build-linux/lib/libclang.so</LibClangPathogenPathLinux>
1011
<PathogenExtensionsCppPath>$(MSBuildThisFileDirectory)../external/llvm-project/clang/tools/libclang/PathogenExtensions.cpp</PathogenExtensionsCppPath>
1112
<LicenseFilePath>$(MSBuildThisFileDirectory)../external/llvm-project/clang/LICENSE.TXT</LicenseFilePath>
1213

@@ -33,17 +34,36 @@
3334
<None Condition="Exists('$(PathogenExtensionsCppPath)')" Include="$(PathogenExtensionsCppPath)" Link="PathogenExtensions.cpp" />
3435
<None Condition="Exists('$(LicenseFilePath)')" Include="$(LicenseFilePath)" Link="LICENSE.txt" Pack="true" PackagePath="LICENSE.txt" />
3536
</ItemGroup>
36-
<ItemGroup Condition="Exists('$(LibClangPathogenPath)')">
37-
<None Include="$(LibClangPathogenPath)" Link="libclang-pathogen.dll">
37+
<ItemGroup>
38+
<None Include="$(LibClangPathogenPathWindows)" Link="libclang-pathogen.dll" Condition="Exists('$(LibClangPathogenPathWindows)')">
3839
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3940
<Pack>true</Pack>
4041
<PackagePath>runtimes/win-x64/native/libclang-pathogen.dll</PackagePath>
4142
</None>
43+
<None Include="$(LibClangPathogenPathLinux)" Link="libclang-pathogen.so" Condition="Exists('$(LibClangPathogenPathLinux)')">
44+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
45+
<Pack>true</Pack>
46+
<PackagePath>runtimes/linux-x64/native/libclang-pathogen.so</PackagePath>
47+
</None>
4248
</ItemGroup>
4349
<!-- Error if native runtime needs to be built or llvm-project is missing -->
4450
<Target Name="_NativeRuntimeChecks" BeforeTargets="Build;Pack">
4551
<Error Text="PathogenExtensions.cpp is missing, ensure Git submodules are up-to-date." Condition="!Exists('$(PathogenExtensionsCppPath)')" />
4652
<Error Text="Clang LICENSE.TXT is missing, ensure Git submodules are up-to-date." Condition="!Exists('$(LicenseFilePath)')" />
47-
<Error Text="Custom libclang.dll is missing, run `build-native.cmd` in the solution root to build it." Condition="!Exists('$(LibClangPathogenPath)')" />
53+
54+
<PropertyGroup>
55+
<_AllRuntimesPresent>true</_AllRuntimesPresent>
56+
<_AnyRuntimePresent>false</_AnyRuntimePresent>
57+
<!-- Check Windows runtime -->
58+
<_AllRuntimesPresent Condition="!Exists('$(LibClangPathogenPathWindows)')">false</_AllRuntimesPresent>
59+
<_AnyRuntimePresent Condition="Exists('$(LibClangPathogenPathWindows)')">true</_AnyRuntimePresent>
60+
<!-- Check Linux runtime -->
61+
<_AllRuntimesPresent Condition="!Exists('$(LibClangPathogenPathLinux)')">false</_AllRuntimesPresent>
62+
<_AnyRuntimePresent Condition="Exists('$(LibClangPathogenPathLinux)')">true</_AnyRuntimePresent>
63+
</PropertyGroup>
64+
<!-- CI builds must have all runtimes present -->
65+
<Error Text="One or more native runtimes are missing, all runtimes are required for CI builds." Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(_AllRuntimesPresent)' != 'true'" />
66+
<!-- For non-CI builds, at least one runtime must be present -->
67+
<Error Text="No native runtimes found, at least one native runtime must be built using `build-native.cmd` or `build-native.sh`." Condition="'$(ContinuousIntegrationBuild)' != 'true' and '$(_AnyRuntimePresent)' != 'true'" />
4868
</Target>
4969
</Project>

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
This repo contains C# bindings for the [libclang Pathogen Extensions](https://github.com/InfectedLibraries/llvm-project) as well as other utilities used by Biohazrd for interacting with ClangSharp.
88

9-
Currently this project targets libclang 10.0.0 and ClangSharp 10.0.0-beta. Currently the NuGet package only supports Windows x64, but the native components can be manually built for Linux x64.
9+
Currently this project targets libclang 10.0.0 and ClangSharp 10.0.0-beta. The NuGet package is currently built for Windows x64 and Linux x64 (glibc >= 2.27).
1010

1111
## License
1212

@@ -39,7 +39,7 @@ If [sccache](https://github.com/mozilla/sccache) (0.2.15 recommended) is present
3939

4040
## Building - Linux
4141

42-
Ubuntu 20.04 Focal x64 is recommended.
42+
Ubuntu 20.04 Focal x64 is recommended for development, Ubuntu 18.04 Bionic x64 is used for CI builds.
4343

4444
### Prerequisites
4545

@@ -57,8 +57,8 @@ If [sccache](https://github.com/mozilla/sccache) (0.2.15 recommended, download t
5757

5858
1. Ensure Git submodules are up-to-date with `git submodule update --init --recursive`
5959
2. Run `build-native.sh` (This will take quite a while the first time.)
60-
61-
You can build and pack the managed components using the .NET SDK (IE: `dotnet build`), however the `ClangSharp.Pathogen.Runtime` project will fail due to the fact that it currently expects the Windows native runtime to be present. (Linux NuGet packages are sitll a work in progress.)
60+
3. Build the managed components using `dotnet build`
61+
4. If desired, pack the NuGet packages using `dotnet pack`
6262

6363
## Development
6464

0 commit comments

Comments
 (0)