Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/update-version-number.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ jobs:

- name: Update README.md ${{ steps.configure.outputs.git-tag }}
run: |
ruby -i -pe 'gsub(%r{(https://github.com/hadashiA/VitalRouter.git\?path=/src/MRubyCS.Unity/Assets/MRubyCS.Compiler.Unity#)[\d\.]+}, %q{\1${{ steps.configure.outputs.git-tag }}})' README.md
ruby -i -pe 'gsub(%r{(https://github.com/hadashiA/VitalRouter.git\?path=/src/MRubyCS.Unity/Assets/MRubyCS.Serializer.Unity#)[\d\.]+}, %q{\1${{ steps.configure.outputs.git-tag }}})' README.md
ruby -i -pe 'gsub(%r{(https://github.com/hadashiA/MRubyCS.git\?path=src/MRubyCS.Unity/Assets/MRubyCS.Compiler.Unity#)[\d\.]+}, %q{\1${{ steps.configure.outputs.git-tag }}})' README.md
ruby -i -pe 'gsub(%r{(https://github.com/hadashiA/MRubyCS.git\?path=src/MRubyCS.Unity/Assets/MRubyCS.Serializer.Unity#)[\d\.]+}, %q{\1${{ steps.configure.outputs.git-tag }}})' README.md
- name: Update package.json ${{ steps.configure.outputs.git-tag }}
run: |
ruby -i -pe 'gsub(/"version"\s*:\s*"([\w\.-]+)"/, %q{"version": "${{ steps.configure.outputs.git-tag }}"})' src/MRubyCS.Unity/Assets/MRubyCS.Compiler.Unity/package.json
Expand Down
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,35 @@ Please refer to the following for the [benchmark code](https://github.com/hadash
> [!NOTE]
> Requirements: Unity 2021.3 or later.

1. Install [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity).
2. Install following packages via NugetForUnity
1. Install [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity) (v4.3.0 or later — required for native plugin support).
2. Install following packages via NuGetForUnity
- Utf8StringInterpolation
- MRubyCS
- (Optional) MRubyCS.Compiler — runtime Ruby compiler. Native binaries (macOS / Linux / Windows) ship inside the NuGet package.
- (Optional) MRubyCS.Serializer
3. (Optional) To install utilities for generating mrb bytecode, refer to the [Compiling and Executing Ruby Code](#compiling-and-executing-ruby-code) section.
3. (Optional) For an Editor extension that auto-imports `.rb` / `.mrb` files as `TextAsset` subassets, install `MRubyCS.Compiler` Unity package as well — see [Unity AssetImporter](#unity-assetimporter).

> [!IMPORTANT]
> **macOS Editor users** — NuGetForUnity v4.3.0's default `NativeRuntimeSettings` ships broken Editor settings for the `osx-arm64` / `osx-x64` runtimes (the Apple Silicon variant has no Editor target, and the Intel variant defaults to "Any CPU"), so `libmruby.dylib` may fail to load in the Editor.
>
> A fix has been submitted upstream — [NuGetForUnity#755](https://github.com/GlitchEnzo/NuGetForUnity/pull/755). Once that is merged and released, this workaround will no longer be needed. In the meantime, open `ProjectSettings/Packages/com.github-glitchenzo.nugetforunity/NativeRuntimeSettings.json` and make sure the two `osx-*` entries look like this, then reimport the dylibs under `Assets/Packages/MRubyCS.Compiler.*/runtimes/osx-*/native/`:
>
> ```json
> {
> "cpuArchitecture": "x86_64",
> "editorCpuArchitecture": "x86_64",
> "editorOperatingSystem": "OSX",
> "runtime": "osx-x64",
> "supportedPlatformTargets": ["StandaloneOSX"]
> },
> {
> "cpuArchitecture": "ARM64",
> "editorCpuArchitecture": "ARM64",
> "editorOperatingSystem": "OSX",
> "runtime": "osx-arm64",
> "supportedPlatformTargets": ["StandaloneOSX"]
> }
> ```

## Basic Usage

Expand Down Expand Up @@ -313,12 +336,16 @@ NOTE: This is a wrapper for native compilers. Currently, only the following plat
dotnet add package MRubyCS.Compiler
```

**Unity**: Open the Package Manager window by selecting Window > Package Manager, then click on [+] > Add package from git URL and enter the following URL:
**Unity**: install `MRubyCS.Compiler` via [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity) (v4.3.0 or later). The native compiler binaries (`libmruby.dylib` / `.so` / `.dll`) are bundled in the NuGet package and resolved automatically.

If you also want the Editor extension that auto-imports `.rb` / `.mrb` files as `TextAsset` subassets, additionally install the Unity package. Open Window > Package Manager, click [+] > Add package from git URL, and enter:

```
https://github.com/hadashiA/MRubyCS.git?path=src/MRubyCS.Unity/Assets/MRubyCS.Compiler.Unity#0.50.3
https://github.com/hadashiA/MRubyCS.git?path=src/MRubyCS.Unity/Assets/MRubyCS.Compiler.Unity#0.106.0
```

See [Unity AssetImporter](#unity-assetimporter) for details.

```cs
using MRubyCS.Compiler;

Expand Down Expand Up @@ -1439,7 +1466,7 @@ By introducing the following packages, serialization of Unity-specific types wil
Open the Package Manager window by selecting Window > Package Manager, then click on [+] > Add package from git URL and enter the following URL:

```
https://github.com/hadashiA/MRubyCS.git?path=src/MRubyCS.Unity/Assets/MRubyCS.Serializer.Unity#0.18.1
https://github.com/hadashiA/MRubyCS.git?path=src/MRubyCS.Unity/Assets/MRubyCS.Serializer.Unity#0.106.0
```

| mruby | C# |
Expand Down
51 changes: 22 additions & 29 deletions src/MRubyCS.Compiler/MRubyCS.Compiler.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0;net10.0;netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RuntimeIdentifiers>osx-arm64</RuntimeIdentifiers>
<LangVersion>9</LangVersion>
<LangVersion>13</LangVersion>
<Description>Native binding for the mruby compiler for use from C# and MRubyCS</Description>
</PropertyGroup>

Expand All @@ -17,37 +17,30 @@
<ProjectReference Include="..\MRubyCS\MRubyCS.csproj" />
</ItemGroup>

<ItemGroup>
<NativeLibs Include="runtimes\**\*.dll" />
<NativeLibs Include="runtimes\**\*.so" />
<NativeLibs Include="runtimes\**\*.a" />
<NativeLibs Include="runtimes\**\*.dylib" />
<None Include="@(NativeLibs)">
<Pack>true</Pack>
<PackageCopyToOutput>true</PackageCopyToOutput>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- Copy files for Unity -->
<ItemGroup>
<None Include="runtimes\**\*.dll;runtimes\**\*.so;runtimes\**\*.dylib;runtimes\**\*.a">
<Pack>true</Pack>
<PackagePath>%(Identity)</PackagePath>
</None>
</ItemGroup>

<PropertyGroup>
<UnityAssetsRoot>$(MSBuildProjectDirectory)\..\MRubyCS.Unity\Assets\MRubyCS.Compiler.Unity\Runtime</UnityAssetsRoot>
<_MRubyCompilerHostRid Condition="'$(RuntimeIdentifier)' != ''">$(RuntimeIdentifier)</_MRubyCompilerHostRid>
<_MRubyCompilerHostRid Condition="'$(_MRubyCompilerHostRid)' == ''">$(NETCoreSdkRuntimeIdentifier)</_MRubyCompilerHostRid>
</PropertyGroup>
<ItemGroup>
<UnityAssets Include="**\*.cs" Exclude="**\bin\**\*.*;**\obj\**\*.*" />
<UnityAssetsPlugins Include="runtimes\**\*.dll" Exclude="**\bin\**\*.*;**\obj\**\*.*" />
<UnityAssetsPlugins Include="runtimes\**\*.so" Exclude="**\bin\**\*.*;**\obj\**\*.*" />
<UnityAssetsPlugins Include="runtimes\**\*.a" Exclude="**\bin\**\*.*;**\obj\**\*.*" />
<UnityAssetsPlugins Include="runtimes\**\*.dylib" Exclude="**\bin\**\*.*;**\obj\**\*.*" />
<ItemGroup Condition="'$(_MRubyCompilerHostRid)' != '' And Exists('runtimes\$(_MRubyCompilerHostRid)\native')">
<None Update="runtimes\$(_MRubyCompilerHostRid)\native\libmruby.*">
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="@(UnityAssets)"
DestinationFiles="$(UnityAssetsRoot)\%(RecursiveDir)%(Filename)%(Extension)"
SkipUnchangedFiles="true" />
<Copy SourceFiles="@(UnityAssetsPlugins)"
DestinationFiles="$(UnityAssetsRoot)\Plugins\%(RecursiveDir)%(Filename)%(Extension)"
SkipUnchangedFiles="true" />

</Target>

</Project>
48 changes: 0 additions & 48 deletions src/MRubyCS.Compiler/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,54 +56,6 @@ unsafe class NativeMethods
public const int Ok = 0;
public const int Failed = 11;

#if !UNITY_2021_3_OR_NEWER
static NativeMethods()
{
NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, DllImportResolver);
}

static IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
if (libraryName == DllName)
{
var path = "runtimes";
string extname;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
path = Path.Join(path, "win");
extname = ".dll";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
path = Path.Join(path, "osx");
extname = ".dylib";
}
else
{
path = Path.Join(path, "linux");
extname = ".so";
}

switch (RuntimeInformation.ProcessArchitecture)
{
case Architecture.X86:
path += "-x86";
break;
case Architecture.X64:
path += "-x64";
break;
case Architecture.Arm64:
path += "-arm64";
break;
}

path = Path.Join(path, "native", $"{DllName}{extname}");
return NativeLibrary.Load(Path.Combine(AppContext.BaseDirectory, path), assembly, searchPath);
}
return IntPtr.Zero;
}
#endif
[DllImport(DllName, EntryPoint = "mrb_open", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern MrbState* MrbOpen();

Expand Down
4 changes: 4 additions & 0 deletions src/MRubyCS.Serializer/MRubyCS.Serializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

<ItemGroup>
<ProjectReference Include="..\MRubyCS\MRubyCS.csproj" />
<ProjectReference Include="..\MRubyCS.Serializer.SourceGenerator\MRubyCS.Serializer.SourceGenerator.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>

<!-- Bundle SourceGenerator -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "MRubyCS.Compiler.Editor",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"MRubyCS.dll",
"MRubyCS.Compiler.dll"
],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions src/MRubyCS.Unity/Assets/MRubyCS.Compiler.Unity/Runtime.meta

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading