# Building Jellyfin 12.1 and .NET 10 on FreeBSD 15.1

## Overview

This documents the process of creating FreeBSD ports for **Jellyfin 12.1** (multimedia/jellyfin) and **.NET 10** (lang/dotnet10) on FreeBSD 15.1-RELEASE.

Jellyfin 12.1 was released September 14, 2026 and targets **.NET 10** (runtime 10.0.10, SDK 10.0.110). This required updating both the Jellyfin port and creating a new .NET 10 port since the existing lang/dotnet was at version 9.0.14.

---

## Initial Problems

### 1. No .NET 10 Port Existed

FreeBSD's lang/dotnet was at 9.0.14. Jellyfin 12.1 requires .NET 10. The existing port structure couldn't simply be version-bumped because:
- Other ports might depend on .NET 9
- Major version upgrades need separate ports (lang/dotnet8, lang/dotnet9, lang/dotnet10 pattern)

### 2. .NET 10 Not Available in FreeBSD Packages

Microsoft doesn't provide official FreeBSD binaries. The community maintains ports via source builds from `dotnet/dotnet` repo. The existing port used a complex bootstrap chain requiring .NET 9 to build .NET 10.

### 3. Bootstrap SDK Failure on FreeBSD 15

The original dotnet port used .NET 9.0.110 SDK (built for FreeBSD 13) as bootstrap. On FreeBSD 15, this failed:
```
Failed to create CoreCLR, HRESULT: 0x8007FF02
```
The bootstrap SDK's `dotnet` binary wouldn't run on FreeBSD 15 due to libc/kernel ABI changes.

### 4. Source Build Runtime RID Mismatch

The source build targets `freebsd.14-x64` but FreeBSD 15 reports `freebsd.15-x64`. NuGet packages in the source-built artifacts had RID-specific names that didn't match:
```
Unable to resolve 'runtime.freebsd-x64.microsoft.netcore.ilasm (>= 10.0.10)'
```

### 5. F# Build Failure (fsyacc/fslex)

The F# compiler build failed with parser generator conflicts:
```
reduce/reduce error at state 1728 on terminal EXTERN...
378 shift/reduce conflicts
811 reduce/reduce conflicts
```
This is a known issue with F# parser generators on newer toolchains.

### 6. Web UI Build Failure (Node.js 24 + sass)

Jellyfin 12.1's web UI uses sass 1.102.0 which has compatibility issues with Node.js 24:
```
sass --embedded is unavailable in pure JS mode.
Error: write EPIPE
```

### 7. Self-Contained Publish Missing Runtime Packs

The portable .NET 10 SDK from community builds doesn't include all runtime packs needed for self-contained publishing. Framework-dependent publish works but self-contained fails with hundreds of "Could not copy file" errors for ASP.NET Core runtime assemblies.

---

## Solutions Implemented

### 1. New lang/dotnet10 Port (Separate from lang/dotnet)

Created `port/dotnet10/` following FreeBSD's versioned port pattern:
- `PORTNAME=dotnet10`
- `DISTVERSION=10.0.14` (runtime), `SDKVERSION=10.0.110`
- Uses pre-built **portable .NET 10 SDK** from `sec/dotnet-core-freebsd-source-build` (10.0.110-vmr)
- Uses **portable source-built artifacts** (RID: `freebsd-x64`) matching FreeBSD 15

Key Makefile changes:
```make
SDK_RID=freebsd-${DOTNET_ARCH}          # portable RID, not freebsd.14-
BOOTSTRAP_SDKVERSION=${SDKVERSION}       # use .NET 10 SDK as bootstrap
SOURCEBUILT_ARTIFACTS_DISTNAME=...freebsd-${DOTNET_ARCH}
NO_BUILD=yes                             # just extract pre-built artifacts
```

### 2. Portable SDK as Bootstrap

Instead of building .NET 10 from source (which takes 4+ hours and has F# issues), use the pre-built portable SDK from `sec/dotnet-core-freebsd-source-build/releases/tag/10.0.110-vmr`:
- `dotnet-sdk-10.0.110-freebsd-x64.tar.gz` - works on FreeBSD 15
- `Private.SourceBuilt.Artifacts.10.0.110-servicing.26326.116.freebsd-x64.tar.gz` - source-built NuGet packages with portable RID

### 3. jellyfin 12.1 Port Updates

Updated `port/jellyfin/Makefile`:
```make
DISTVERSION=12.1
GH_TAGNAME=v12.1
BUILD_DEPENDS=dotnet:lang/dotnet10
TEST_DEPENDS=dotnet:lang/dotnet10
DOTNET_RUNTIME=freebsd-x64
```

Regenerated NuGet dependencies (213 packages) for .NET 10:
```bash
cd jellyfin-12.1
for proj in $(dotnet sln list | grep '\.csproj$'); do
    dotnet list "$proj" package --include-transitive --format json \
        | jq -r '.projects[0].frameworks[] | ((.topLevelPackages //[]) + (.transitivePackages //[]))[] | "NUPKG_NUGET+=\(.id):\(.resolvedVersion)"'
done | sort -u > nupkg_nuget.mk
```

### 4. Web UI Build Fix

The sass/Node.js 24 EPIPE issue was resolved by:
```bash
cd jellyfin-web-12.1
npm install sass-embedded@latest --save-dev
NODE_OPTIONS="--max-old-space-size=4096" npm run build:production
```
The `sass-embedded` package provides the Dart Sass binary that Node.js 24 can use.

### 5. Framework-Dependent Publish

Since self-contained publish requires runtime packs not present in portable SDK, used framework-dependent publish:
```bash
dotnet publish Jellyfin.Server \
    --runtime freebsd-x64 \
    --configuration Release \
    --packages ../packages \
    -o bin/publish \
    "-p:DebugSymbols=false;DebugType=none;UseAppHost=true;PublishReadyToRun=false"
# Note: NO --self-contained flag
```

This produces a working binary that uses the system-installed `dotnet10` runtime.

### 6. libskiasharp Dependency

Jellyfin uses SkiaSharp for image processing. The port already had `libskiasharp` as a dependency:
```make
LIB_DEPENDS=libSkiaSharp.so:graphics/libskiasharp
```

The FreeBSD `graphics/libskiasharp` port (version 3.119.x) works correctly with Jellyfin 12.1. No changes needed.

---

## Port Files Summary

### port/dotnet10/
```
dotnet10/
├── Makefile        # 68 lines, NO_BUILD=yes, extracts pre-built artifacts
├── distinfo        # SHA256 for SDK + source-built artifacts
├── pkg-plist       # Auto-generated with %%DATADIR%% prefix
├── pkg-descr       # Standard description
└── files/          # Patches (openssl already upstreamed in .NET 10)
```

### port/jellyfin/
```
jellyfin/
├── Makefile            # DISTVERSION=12.1, depends on lang/dotnet10
├── distinfo            # 213 NuGet packages + node modules
├── nupkg_nuget.mk      # Regenerated for .NET 10
├── pkg-plist           # Generated from published output
├── nuget.mk            # NuGet fetch helper
├── files/
│   ├── jellyfin.in         # RC script (updated for dotnet10)
│   ├── patch-nuget.config  # Points to /usr/local/share/dotnet10/packs
│   └── *.patch             # Hardware acceleration patches (VAPI/QSV/Vulkan)
└── work/               # Build artifacts (excluded from fossil)
```

---

## Testing Results

### dotnet10
```bash
pkg add port/dotnet10/work/pkg/dotnet10-10.0.14.pkg
dotnet --version
# 10.0.110
```

### jellyfin
```bash
pkg add port/jellyfin/work/pkg/jellyfin-12.1.pkg
jellyfin --version
# Jellyfin.Server 12.1.0.0
```

Both install and run on FreeBSD 15.1-RELEASE.

---

## Upstream Acceptance Requirements

For these ports to be accepted into the FreeBSD ports tree:

### 1. distinfo Verification
- All SHA256/SIZE entries must be verified against official sources
- Current distinfo uses community-built artifacts from `sec/dotnet-core-freebsd-source-build`
- Upstream prefers official Microsoft sources or FreeBSD-built artifacts

### 2. Build from Source (Not Pre-built)
- The dotnet10 port currently extracts pre-built community artifacts
- FreeBSD ports policy prefers building from source
- Would need to implement proper source build in the port (4+ hour build)
- Requires fixing F# build (fsyacc/fslex conflicts)

### 3. Port Maintenance
- Need a maintainer (currently `arrowd@FreeBSD.org` for dotnet, `bapt@FreeBSD.org` for jellyfin)
- Regular updates for .NET servicing releases
- Security updates tracking

### 4. F# Build Fix
The F# compiler build fails with parser generator conflicts. Options:
- Patch fsyacc/fslex grammar files
- Disable F# in the build (not ideal, F# is part of .NET SDK)
- Use pre-built F# compiler as bootstrap

### 5. Hardware Acceleration Patches
The jellyfin patches for FreeBSD VAPI/QSV/Vulkan support:
```patch
# OperatingSystem.IsLinux() → OperatingSystem.IsLinux() || OperatingSystem.IsFreeBSD()
```
Should be submitted upstream to jellyfin/jellyfin to avoid carrying patches.

### 6. libskiasharp Version
Current port depends on `graphics/libskiasharp` (3.119.x). Verify compatibility with each Jellyfin update.

### 7. RC Script Updates
The `files/jellyfin.in` RC script uses:
```bash
CLR_OPENSSL_VERSION_OVERRIDE=30
```
May need adjustment for .NET 10 (possibly 35).

### 8. Package Testing
- Test on FreeBSD 14.x (still supported)
- Test on arm64 (currently marked BROKEN for aarch64 due to crossgen2 segfault)
- Test in jails with/without VNET

### 9. Port Makefile Polish
- Remove `NO_BUILD=yes` once source build works
- Add proper `CONFLICTS` with other dotnet versions
- Ensure `USES` and `RUN_DEPENDS` are minimal and correct
- Add `OPTIONS_DEFINE` for optional features

---

## References

- [FreeBSD dotnet port](https://github.com/freebsd/freebsd-ports/tree/main/lang/dotnet)
- [sec/dotnet-core-freebsd-source-build](https://github.com/sec/dotnet-core-freebsd-source-build)
- [Thefrank/dotnet-freebsd-crossbuild](https://github.com/Thefrank/dotnet-freebsd-crossbuild)
- [Jellyfin 12.1 Release](https://github.com/jellyfin/jellyfin/releases/tag/v12.1)
- [FreeBSD Porter's Handbook](https://docs.freebsd.org/en/books/porters-handbook/)

---

## Conclusion

The ports work and produce functional packages. The main blockers for upstream acceptance are:
1. **Source build requirement** - current port uses pre-built binaries
2. **F# build failure** - parser generator conflicts on FreeBSD 15
3. **Community artifact dependency** - relies on sec's builds, not official sources

With a dedicated maintainer and build infrastructure, these are solvable. The foundation is solid: both packages build, install, and run on FreeBSD 15.1.