Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: packaging native runtime libs #2781

Merged
merged 56 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
42bdafd
packaging native runtime libs
vaind Nov 2, 2023
7aeecfc
build sentry-native in CI
vaind Nov 3, 2023
a50766a
fix build-sentry-native.ps1
vaind Nov 3, 2023
e42c103
rename ci job
vaind Nov 3, 2023
05e7300
fix windows build of sentry-native
vaind Nov 3, 2023
0eec224
cache sentry-native build
vaind Nov 3, 2023
5594899
fix build job
vaind Nov 3, 2023
a7708bd
use cache to transfer artifacts
vaind Nov 3, 2023
36bab5c
fix
vaind Nov 3, 2023
3b00429
fix git attributes autocrlf on windows for ps1 scripts
vaind Nov 3, 2023
72e1dfb
fix sentry-native restore across OSs
vaind Nov 3, 2023
37c9f53
wip: integration tests
vaind Nov 4, 2023
a6caba6
fix: aot helper
vaind Nov 5, 2023
72ea7d0
fix aot integration test
vaind Nov 5, 2023
893a133
integration test ci
vaind Nov 5, 2023
614e99a
improve AOT integration tests
vaind Nov 5, 2023
f70c219
speed up integration test
vaind Nov 5, 2023
d591d68
todo
vaind Nov 5, 2023
2b3ffb0
ci: build.yml fixes
vaind Nov 6, 2023
cbe73cf
cleanups
vaind Nov 6, 2023
70f7706
integration test fixes
vaind Nov 6, 2023
a5ce6d0
suppress aot warning
vaind Nov 6, 2023
bf7f007
integration test fixes
vaind Nov 6, 2023
f8892ca
fix sentry-native packaging path
vaind Nov 6, 2023
3529509
ci: sparse checkout in integration test
vaind Nov 6, 2023
147ccc0
exclude parent props in the temp dir
vaind Nov 6, 2023
8e4b806
ci: fix sparse checkout
vaind Nov 6, 2023
8a157d2
fix package transitive targets
vaind Nov 6, 2023
e60a214
fix sparse checkout
vaind Nov 6, 2023
fc68386
trailing whitespace
vaind Nov 6, 2023
77ca12c
fix tests
vaind Nov 6, 2023
3984dec
restore workloads
vaind Nov 6, 2023
943e848
fix macos
vaind Nov 6, 2023
b1a2996
fixes
vaind Nov 7, 2023
13f805c
fixes
vaind Nov 7, 2023
9f731b2
fixes
vaind Nov 7, 2023
385547b
move integration tests to a single directory
vaind Nov 7, 2023
7c9d479
linux fixes
vaind Nov 7, 2023
a9f579d
minor changes
vaind Nov 7, 2023
9fcc6bb
install android workload
vaind Nov 7, 2023
8856880
docs
vaind Nov 7, 2023
422e8d8
try to fix maui test
vaind Nov 7, 2023
c656741
Update build.yml
jamescrosswell Nov 8, 2023
2cd789a
Update build.yml
jamescrosswell Nov 8, 2023
66faff5
Reset build.yml
jamescrosswell Nov 8, 2023
6b0f62e
try to fix maui build
vaind Nov 8, 2023
5777a5e
skip maui cli tests for now
vaind Nov 8, 2023
9ff35c1
try to fix maui
vaind Nov 8, 2023
3a2480a
Merge branch 'feat/4.0.0' into chore/native-packaging
vaind Nov 8, 2023
dfd4ac9
cleanup
vaind Nov 8, 2023
df26775
one last chance for maui
vaind Nov 8, 2023
2324356
runtime tests for AOT helper
vaind Nov 8, 2023
46d520c
disable MAUI CLI test
vaind Nov 8, 2023
7fb25e4
Delete src/Sentry/Platforms/Native/runtimes/osx/native/libsentry-nati…
vaind Nov 8, 2023
8318720
fix CLI upload inside sentry repo
vaind Nov 8, 2023
d7e95de
fix test compilation
vaind Nov 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.cs text=auto eol=lf diff=csharp
*.sln text=auto eol=crlf
*.sh eol=lf
*.ps1 eol=lf
CHANGELOG.md merge=union


Expand Down
122 changes: 103 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,34 @@ on:
pull_request:

jobs:
build-sentry-native:
name: sentry-native (${{ matrix.os }})
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu, windows, macos]

steps:
- name: Checkout
uses: actions/checkout@v4

- run: git submodule update --init modules/sentry-native

- uses: actions/cache@v3
id: cache
with:
path: src/Sentry/Platforms/Native/sentry-native
key: sentry-native-${{ runner.os }}-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }}
enableCrossOsArchive: true

- run: scripts/build-sentry-native.ps1
if: steps.cache.outputs.cache-hit != 'true'
shell: pwsh

build:
name: ${{ matrix.os }}
needs: build-sentry-native
name: .NET (${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
Expand All @@ -30,9 +56,42 @@ jobs:

# We use macOS for the final publishing build so we we get all the iOS/macCatalyst targets in the packages
- name: Set Environment Variables
if: startsWith(matrix.os, 'macos') && startsWith(github.ref_name, 'release/')
if: startsWith(matrix.os, 'macos')
run: echo "CI_PUBLISHING_BUILD=true" >> $GITHUB_ENV

- name: Download sentry-native (Linux)
if: ${{ (env.CI_PUBLISHING_BUILD == 'true') || (runner.os == 'Linux') }}
uses: actions/cache/restore@v3
with:
path: src/Sentry/Platforms/Native/sentry-native
key: sentry-native-Linux-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }}
fail-on-cache-miss: true

- name: Download sentry-native (macOS)
if: ${{ (env.CI_PUBLISHING_BUILD == 'true') || (runner.os == 'macOS') }}
uses: actions/cache/restore@v3
with:
path: src/Sentry/Platforms/Native/sentry-native
key: sentry-native-macOS-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }}
fail-on-cache-miss: true

- name: Download sentry-native (Windows)
if: ${{ (env.CI_PUBLISHING_BUILD == 'true') || (runner.os == 'Windows') }}
uses: actions/cache/restore@v3
with:
path: src/Sentry/Platforms/Native/sentry-native
key: sentry-native-Windows-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }}
fail-on-cache-miss: true
enableCrossOsArchive: true

- name: Rebuild Solution Filters
shell: pwsh
run: scripts/generate-solution-filters.ps1

- name: Ensure Solution Filters are up to date
shell: pwsh
run: scripts/dirty-check.ps1 -PathToCheck ./*.sln* -GuidanceOnFailure "Uncommitted changes to the solution filters detected. Run `scripts/generate-solution-filters.ps1` locally and commit changes."

- name: Setup Environment
uses: ./.github/actions/environment

Expand All @@ -46,24 +105,12 @@ jobs:
- name: Restore .NET Dependencies
run: dotnet restore Sentry-CI-Build-${{ runner.os }}.slnf --nologo

- name: Build (for non-release branch)
if: env.CI_PUBLISHING_BUILD != 'true'
run: dotnet build Sentry-CI-Build-${{ runner.os }}.slnf -c Release --no-restore --nologo -flp:logfile=build.log

- name: Build (for release branch)
if: env.CI_PUBLISHING_BUILD == 'true'
- name: Build
run: dotnet build Sentry-CI-Build-${{ runner.os }}.slnf -c Release --no-restore --nologo -flp:logfile=build.log -p:CopyLocalLockFileAssemblies=true
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}

- name: Test
run: dotnet test Sentry-CI-Build-${{ runner.os }}.slnf -c Release --no-build --nologo -l GitHubActions -l "trx;LogFilePrefix=testresults_${{ runner.os }}"

- name: Test symbol upload
uses: getsentry/github-workflows/sentry-cli/integration-test/@v2
with:
path: test

- name: Upload build and test outputs
if: failure()
uses: actions/upload-artifact@v3
Expand All @@ -73,19 +120,56 @@ jobs:

# To save time and disk space, we only create and archive the Nuget packages when we're actually releasing.

- name: Create Nuget Packages (release branch only)
- name: Create Nuget Packages
if: env.CI_PUBLISHING_BUILD == 'true'
run: dotnet pack Sentry-CI-Build-${{ runner.os }}.slnf -c Release --no-build --nologo

- name: Archive Nuget Packages (release branch only)
- name: Archive Nuget Packages
if: env.CI_PUBLISHING_BUILD == 'true'
uses: actions/upload-artifact@v3
with:
name: ${{ github.sha }}
if-no-files-found: error
path: |
${{ github.workspace }}/src/**/Release/*.nupkg
${{ github.workspace }}/src/**/Release/*.snupkg
src/**/Release/*.nupkg
src/**/Release/*.snupkg

integration-test:
needs: build
name: Integration test (${{ matrix.os }})
runs-on: ${{ matrix.os }}-latest

strategy:
fail-fast: false
matrix:
os: [ubuntu, windows, macos]

steps:
# We only check out what is absolutely necessary to reduce a chance of local files impacting integration tests.
- uses: actions/checkout@v4
with:
sparse-checkout: |
jamescrosswell marked this conversation as resolved.
Show resolved Hide resolved
Directory.Build.props
integration-test

- name: Fetch Nuget Packages
uses: actions/download-artifact@v3
with:
name: ${{ github.sha }}
path: src

- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
7.0.x
8.0.x

- run: dotnet workload install android maui-android

- name: Test
uses: getsentry/github-workflows/sentry-cli/integration-test/@v2
with:
path: integration-test

test-solution-filters:
runs-on: ubuntu-latest
Expand Down
22 changes: 17 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ For big feature it's advised to raise an issue to discuss it first.

*If using an M1 ("Apple silicon") processor, read [the special instructions below](#special-instructions-for-apple-silicon-cpus).*

* On Windows:
* On Windows:
- [.NET Framework](https://dotnet.microsoft.com/download/dotnet-framework) 4.6.2 or higher.
- You'll need `CMake` somewhere on your PATH. If you don't already have this, one way to get it is to install the [C++ CMake tools for Windows](https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=msvc-170#installation)
- `Sentry.DiagnosticSource.IntegrationTests.csproj` uses [SQL LocalDb](https://docs.microsoft.com/sql/database-engine/configure-windows/sql-server-express-localdb) - [download SQL LocalDB 2019](https://download.microsoft.com/download/7/c/1/7c14e92e-bdcb-4f89-b7cf-93543e7112d1/SqlLocalDB.msi). To avoid running these tests, unload `Sentry.DiagnosticSource.IntegrationTests.csproj` from the solution.
* On macOS/Linux
- [Mono 6 or higher](https://www.mono-project.com/download/stable) to run the unit tests on the `net4x` targets.
- Install `CMake` using your favourite package manager (e.g. `brew install cmake`)
- Install `CMake` using your favourite package manager (e.g. `brew install cmake`)

## .NET MAUI Requirements

To build any of `Sentry.Maui`, `Sentry.Maui.Tests`, or `Sentry.Samples.Maui`, you'll need to have .NET SDK 7.0.400 or greater installed, and have installed the MAUI workloads installed, either through Visual Studio setup, or by running `dotnet workload restore` (or `dotnet workload install maui`) from the Sentry source code root directory.
You may also need other platform dependencies.
You may also need other platform dependencies.

See https://docs.microsoft.com/dotnet/maui/ for details. JetBrains also have a great blog post if you're developing on a Mac: https://blog.jetbrains.com/dotnet/2022/05/25/macos-environment-setup-for-maui-development/

Expand All @@ -50,11 +50,11 @@ Although the files in `/src/Sentry/Platforms/` are part of the `Sentry` project,

These `*.props` files are used to add platform-specific files, such as references to the binding projects for each native SDK (which provide .NET wrappers around native Android or Cocoa functions).

Also note `/Directory.Build.targets` contains some [convention based rules](https://github.com/getsentry/sentry-dotnet/blob/b1bfe1efc04eb4c911a85f1cf4cd2e5a176d7c8a/Directory.Build.targets#L17-L35) to exclude code that is not relevant for the target platform. Developers using Visual Studio will need to enable `Show All Files` in order to be able to see these files, when working with the solution.
Also note `/Directory.Build.targets` contains some [convention based rules](https://github.com/getsentry/sentry-dotnet/blob/b1bfe1efc04eb4c911a85f1cf4cd2e5a176d7c8a/Directory.Build.targets#L17-L35) to exclude code that is not relevant for the target platform. Developers using Visual Studio will need to enable `Show All Files` in order to be able to see these files, when working with the solution.

## Solution Filters

Most contributors will rarely need to load Sentry.sln. The repository contains various solution filters that will be more practical for day to day tasks.
Most contributors will rarely need to load Sentry.sln. The repository contains various solution filters that will be more practical for day to day tasks.

These solution filters get generated automatically by `/scripts/generate-solution-filters.ps1` so, although you can certainly create your own solution filters and manage these how you wish, don't try to modify any of the `*.slnf` files that are committed to source control. Instead, changes to these can be made by modifying `/scripts/generate-solution-filters-config.yml` and re-running the script that generates these.

Expand Down Expand Up @@ -134,3 +134,15 @@ pwsh ./scripts/accept-verifier-changes.ps1
```

You may need to run this multiple times because `dotnet test` stops after a certain number of failures.

## Integration tests

Directory [./integration-test](./integration-test/) contains [Pester](https://pester.dev/)-based integration tests.
These tests create sample apps with `dotnet new` and run against local nuget packages (.nuget files).
In CI, these packages are expected to be present, while locally, scripts will run `nuget pack` automatically.

### Running integration tests locally

You can run individual tests either via Pester integration (e.g. in VS Code), or from command line: `./integration-test/cli.Tests.ps1`. Consult Pester docs for details on how to write tests.

Because these tests rely on a Sentry server mock (`Invoke-SentryServer`) from <https://github.com/getsentry/github-workflows/tree/main/sentry-cli/integration-test>, you need to check out [getsentry/github-workflows](https://github.com/getsentry/github-workflows) as a sibling directory next to your `getsentry/sentry-dotnet` checkout.
9 changes: 0 additions & 9 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,4 @@
</ItemGroup>
</Target>

<!--
These are needed because we use project references in this solution.
In an app that uses our nuget packages, they will come through the nuget packages automatically.
-->
<Import Project="$(MSBuildThisFileDirectory)src\Sentry\buildTransitive\Sentry.targets" />
<Import Project="$(MSBuildThisFileDirectory)src\Sentry.Bindings.Cocoa\buildTransitive\Sentry.Bindings.Cocoa.targets"
Condition="'$(OutputType)' == 'Exe' And ('$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst')" />
<Import Project="$(MSBuildThisFileDirectory)src\Sentry\Platforms\Native\buildTransitive.targets" />

</Project>
2 changes: 2 additions & 0 deletions integration-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*-app
packages
3 changes: 3 additions & 0 deletions integration-test/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<!-- Don't include parent Directory.Build.props -->
</Project>
3 changes: 3 additions & 0 deletions integration-test/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<!-- Don't include parent Directory.Build.targets -->
</Project>
Loading