Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
32 changes: 25 additions & 7 deletions .github/workflows/build-test-distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ jobs:
internal_build: ${{ needs.config.outputs.internal_build == 'true' }}
upload_artifacts: ${{ needs.config.outputs.upload_artifacts == 'true' }}
upload_test_artifacts: ${{ needs.config.outputs.upload_test_artifacts == 'true' }}
nuget_build_patch: ${{ needs.config.outputs.build_enable_windows == 'true' && needs.config.outputs.upload_artifacts == 'true'}}
secrets: inherit

update-win-version:
Expand All @@ -149,6 +150,7 @@ jobs:
- config
- windows-build-test
- linux-vcpkg-build-test
- macos-build-test
timeout-minutes: 20
runs-on: windows-2025
steps:
Expand All @@ -158,16 +160,32 @@ jobs:
- name: Download NuGet Windows Patch Archive
uses: actions/download-artifact@v7
with:
pattern: DotNetPatchArchiveWindows*
pattern: DotNetPatchArchiveWindows-x64
path: windows_runtime
merge-multiple: true

- name: Download NuGet Linux Patch Archive
- name: Download NuGet Linux x64 Patch Archive
uses: actions/download-artifact@v7
with:
pattern: DotNetPatchArchiveLinux*
path: linux_runtime
merge-multiple: true
pattern: DotNetPatchArchiveLinux-x64
path: linux_x64_runtime

- name: Download NuGet Linux Arm Patch Archive
uses: actions/download-artifact@v7
with:
pattern: DotNetPatchArchiveLinux-arm64
path: linux_arm64_runtime

- name: Download NuGet MacOS x64 Patch Archive
uses: actions/download-artifact@v7
with:
pattern: DotNetPatchArchiveMacOs-x64
path: macos_x64_runtime

- name: Download NuGet MacOS Arm Patch Archive
uses: actions/download-artifact@v7
with:
pattern: DotNetPatchArchiveMacOs-arm64
path: macos_arm64_runtime

- name: Download NuGet DLL
uses: actions/download-artifact@v7
Expand All @@ -179,7 +197,7 @@ jobs:
- name: Generate NuGet specification
run: |
echo ${{ needs.config.outputs.app_version }}
py -3 scripts\nuget_patch\generate_nuget_spec.py dotnet_dll windows_runtime linux_runtime ${{ needs.config.outputs.app_version }}
py -3 scripts\nuget_patch\generate_nuget_spec.py dotnet_dll windows_runtime linux_x64_runtime linux_arm64_runtime macos_x64_runtime macos_arm64_runtime ${{ needs.config.outputs.app_version }}

- name: Download NuGet Executable
run: curl https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -o nuget.exe
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-test-linux-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ jobs:
stats_file_suffix: -${{ steps.collect-runner-stats.outputs.job_id }}

- name: Create and fix fake Wheel for NuGet
if: ${{ inputs.nuget_build_patch && matrix.arch == 'x64' && matrix.compiler == 'Clang 20' && matrix.config == 'Release' }}
if: ${{ inputs.nuget_build_patch && matrix.compiler == 'Clang 20' && matrix.config == 'Release' }}
shell: bash
run: |
python3 -m venv ./wheel_venv
Expand All @@ -273,9 +273,9 @@ jobs:
python3 ./scripts/nuget_patch/patch_library_deps.py "./build/Release/bin/libMeshLibC2.so" "./patched_content/"

- name: Upload NuGet files to Artifacts
if: ${{ inputs.nuget_build_patch && matrix.arch == 'x64' && matrix.compiler == 'Clang 20' && matrix.config == 'Release' }}
if: ${{ inputs.nuget_build_patch && matrix.compiler == 'Clang 20' && matrix.config == 'Release' }}
uses: actions/upload-artifact@v6
with:
name: DotNetPatchArchiveLinux-x64
name: DotNetPatchArchiveLinux-${{ matrix.arch }}
path: ./patched_content/*
retention-days: 1
27 changes: 24 additions & 3 deletions .github/workflows/build-test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ on:
default: true
required: false
type: boolean
nuget_build_patch:
default: false
required: false
type: boolean

jobs:
macos-build-test:
Expand Down Expand Up @@ -84,14 +88,14 @@ jobs:
echo "Brew prefix: $BREW_PREFIX"
echo "brew-prefix=$BREW_PREFIX" >> $GITHUB_OUTPUT
echo "BREW_PREFIX=$BREW_PREFIX" >> $GITHUB_ENV

# Substitute BREW_PREFIX in templates and set actual compiler paths
CXX_COMPILER=$(echo "${{ matrix.cxx-compiler-template }}" | sed "s|BREW_PREFIX|$BREW_PREFIX|g")
C_COMPILER=$(echo "${{ matrix.c-compiler-template }}" | sed "s|BREW_PREFIX|$BREW_PREFIX|g")

echo "CXX compiler: $CXX_COMPILER"
echo "C compiler: $C_COMPILER"

echo "cxx-compiler=$CXX_COMPILER" >> $GITHUB_OUTPUT
echo "c-compiler=$C_COMPILER" >> $GITHUB_OUTPUT

Expand Down Expand Up @@ -262,3 +266,20 @@ jobs:
artifact_path: ${{ github.workspace }}
artifact_glob: meshlib_${{matrix.os}}.pkg
stats_file_suffix: -${{ steps.collect-runner-stats.outputs.job_id }}

- name: Create and fix fake Wheel for NuGet
if: ${{ inputs.nuget_build_patch && matrix.config == 'Release' }}
shell: bash
run: |
python3 -m venv ./wheel_venv
source ./wheel_venv/bin/activate
python3 -m pip install delocate==0.10.7
python3 ./scripts/nuget_patch/patch_library_deps.py "./build/Release/bin/libMeshLibC2.dylib" "./patched_content/"

- name: Upload NuGet files to Artifacts
if: ${{ inputs.nuget_build_patch && matrix.config == 'Release' }}
uses: actions/upload-artifact@v6
with:
name: DotNetPatchArchiveMacOs-${{ matrix.arch }}
path: ./patched_content/*
retention-days: 1
40 changes: 14 additions & 26 deletions docs/testing_local_nuget_packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,31 @@ Create a file called `NuGet.Config` in the same directory as the `.csproj` proje

Here `"local-packages"` can be any string, and `"nuget"` is the directory name where you'll put the package, relative to the current directory (where this config file is placed).

### Create the local feed
### Copy the package to the local feed

The `./nuget` directory is called the "local feed", a place where nuget can install packages from.

In theory, the contents must be created using the `nuget ...` command, but installing it on Linux is tricky, so we'll do it manually.
To properly copy the package into it, run: `dotnet nuget push MeshLib_v1.2.3.4.nupkg --source "$(realpath nuget)"`.

We want the following hierarchy: (replace `1.2.3.4` with your version)
The last parameter is the absolute path to this `nuget` directory, you can pass it manually instead of using `realpath`.

```
nuget
└── meshlib
└── 1.2.3.4
├── meshlib.1.2.3.4.nupkg
├── meshlib.1.2.3.4.nupkg.sha512
└── MeshLib.nuspec
```
If done correctly, the package will be copied into `./nuget/MeshLib.1.2.3.4.nupkg` (notice it being automatically renamed). You can copy it yourself there too.

Create the directory `nuget/meshlib/1.2.3.4`. Note that the package name must be in lowercase.
### Install package

Copy your `MeshLib_v1.2.3.4.nupkg` into `nuget/meshlib/1.2.3.4/meshlib.1.2.3.4.nupkg`. Note that the package name must be changed to lowercase, and `_v` replaced with `.`.
Delete the existing MeshLib packages:

Create the `.sha512` file using:
```sh
sha512sum nuget/meshlib/1.2.3.4/meshlib.1.2.3.4.nupkg >nuget/meshlib/1.2.3.4/meshlib.1.2.3.4.nupkg.sha512
```
* On Windows, delete `C:\Users\user\.nuget\packages\meshlib`.

`MeshLib.nuspec` must be unzipped from `.nupkg`, which is just a ZIP archive. Do that using:
```sh
unzip nuget/meshlib/1.2.3.4/meshlib.1.2.3.4.nupkg -d nuget/meshlib/1.2.3.4/ MeshLib.nuspec
```
### Install package
* On Linux: `rm -rf ~/.nuget/packages/meshlib/`

Delete the existing MeshLib packages using:
```sh
rm -rf ~/.nuget/packages/meshlib/
If this is a new project, add the dependency on MeshLib by adding the following part to the `.csproj` file:
```xml
<ItemGroup>
<PackageReference Include="MeshLib" Version="1.2.3.4" />
</ItemGroup>
```

Run the project. NuGet will automatically install your package into `~/.nuget/packages/meshlib/1.2.3.4`.

Now the `./nuget` directory and the `NuGet.Config` file are no longer needed.
Now the `./nuget` directory and the `NuGet.Config` file are no longer needed, and neither is the original package file that was passed to `dotnet nuget push ...`.
8 changes: 8 additions & 0 deletions scripts/nuget_patch/MeshLib.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
This file is included for .NET Framework projects (as opposed to newer .NET) to ensure that the native libraries get copied to the build output directory.
-->
<Project>
<ItemGroup Condition="$([MSBuild]::VersionLessThan('$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)'))','5.0'))">
<ContentWithTargetPath Include="$(MSBuildThisFileDirectory)\..\runtimes\win-x64\native\*" TargetPath="%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
33 changes: 22 additions & 11 deletions scripts/nuget_patch/fake_whl_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def make_fake_whl(dll_path : Path):
os.mkdir(whl_dir)
whl_libs_path = whl_dir / "dummy.libs"
whl_info_path = whl_dir / "dummy-1.0.dist-info"
os.mkdir( whl_libs_path)
os.mkdir( whl_libs_path )
os.mkdir( whl_info_path )
# copy dll
shutil.copyfile(dll_path, whl_libs_path / dll_path.name )
Expand All @@ -29,6 +29,14 @@ def make_fake_whl(dll_path : Path):
shutil.rmtree(whl_dir)

def patch_whl(out_dir,libs_dir):
def copy_libs(src_wheel):
temp_dir = Path("patched_whl")
shutil.unpack_archive(src_wheel, temp_dir, "zip")
shutil.copytree(Path(temp_dir) / "dummy.libs", Path(out_dir), dirs_exist_ok=True)
if SYSTEM == "Darwin":
shutil.copytree(Path(temp_dir) / "dummy.dylibs", Path(out_dir), dirs_exist_ok=True)
shutil.rmtree(temp_dir)

# use mangling tool on whl file
# store result dlls in `content/dummy.libs/`
try:
Expand All @@ -53,6 +61,9 @@ def patch_whl(out_dir,libs_dir):
"dummy-1.0-py3-none-any.whl"
]
)
repaired_files = list(Path("wheelhouse").glob("dummy-*.whl"))
copy_libs(repaired_files[0])
shutil.rmtree("wheelhouse")
elif SYSTEM == "Linux":
sys.path.append(libs_dir) # to find SO files
# see also: https://github.com/mayeut/pep600_compliance
Expand All @@ -65,17 +76,17 @@ def patch_whl(out_dir,libs_dir):
"dummy-1.0-py3-none-any.whl"
]
)
repaired_files = list(Path("wheelhouse").glob("dummy-*.whl"))
copy_libs(repaired_files[0])
shutil.rmtree("wheelhouse")
elif SYSTEM == "Darwin":
subprocess.check_call(
["delocate-wheel", "-v", "dummy-1.0-py3-none-any.whl"]
)
copy_libs("dummy-1.0-py3-none-any.whl")
except subprocess.CalledProcessError as e:
print(e)
sys.exit(e.returncode)
# not needed anymore
os.remove("dummy-1.0-py3-none-any.whl")

repaired_files = []
for repaired_wheel_file in Path(".").glob("wheelhouse/dummy-*.whl"):
repaired_files.append(repaired_wheel_file)
shutil.unpack_archive(repaired_files[0],"patched_whl","zip")
shutil.copytree(Path("patched_whl") / "dummy.libs/",Path(out_dir))
#clean
shutil.rmtree("wheelhouse")
shutil.rmtree("patched_whl")
# clean
os.remove("dummy-1.0-py3-none-any.whl")
14 changes: 11 additions & 3 deletions scripts/nuget_patch/generate_nuget_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
WORK_DIR = Path(".")
DOTNET_DLL_DIR = WORK_DIR / sys.argv[1]
WINDOWS_RUNTIME_DIR = WORK_DIR / sys.argv[2]
LINUX_RUNTIME_DIR = WORK_DIR / sys.argv[3]
VERSION = sys.argv[4][1:]
LINUX_X64_RUNTIME_DIR = WORK_DIR / sys.argv[3]
LINUX_ARM_RUNTIME_DIR = WORK_DIR / sys.argv[4]
MACOS_X64_RUNTIME_DIR = WORK_DIR / sys.argv[5]
MACOS_ARM_RUNTIME_DIR = WORK_DIR / sys.argv[6]
VERSION = sys.argv[7][1:]

SPEC_FILE = WORK_DIR / "Package.nuspec"
LICENSE_FILE = WORK_DIR / "LICENSE"
Expand All @@ -29,8 +32,13 @@ def add_files( folder : Path, target ):

FILES = ""
add_files( DOTNET_DLL_DIR, "lib/netstandard2.0/" )

# For platform names, see: https://learn.microsoft.com/en-us/dotnet/core/rid-catalog
add_files( WINDOWS_RUNTIME_DIR, "runtimes/win-x64/native/" )
add_files( LINUX_RUNTIME_DIR, "runtimes/linux-x64/native/" )
add_files( LINUX_X64_RUNTIME_DIR, "runtimes/linux-x64/native/" )
add_files( LINUX_ARM_RUNTIME_DIR, "runtimes/linux-arm64/native/" )
add_files( MACOS_X64_RUNTIME_DIR, "runtimes/osx-x64/native/" )
add_files( MACOS_ARM_RUNTIME_DIR, "runtimes/osx-arm64/native/" )

with open(Path(__file__).parent / "template.nuspec", 'r') as template_file:
updated_nuspec = Template(template_file.read()).substitute(
Expand Down
2 changes: 2 additions & 0 deletions scripts/nuget_patch/template.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<file src="./macos/MeshInspector_icon.png" target="images/"></file>
<file src="LICENSE.txt" target=""></file>
<file src="./readme_dotnet.md" target="docs/"></file>
<file src="./scripts/nuget_patch/MeshLib.targets" target="build/"></file>
<file src="./scripts/nuget_patch/MeshLib.targets" target="buildTransitive/"></file>
$FILES
</files>
</package>
Loading