Skip to content

Commit

Permalink
Finalize 0.0.33
Browse files Browse the repository at this point in the history
  • Loading branch information
olokobayusuf committed Dec 31, 2024
1 parent caf6002 commit 758715a
Show file tree
Hide file tree
Showing 55 changed files with 152 additions and 162 deletions.
2 changes: 1 addition & 1 deletion Assets/Tests/Editor/PredictionTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Editor/PredictorTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Editor/UserTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/AccessKeyTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/FxncVersionTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/GreetingTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/ImageTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/InspectBuildCacheTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/StreamingTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/SystemInfoTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Tests {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Tests.unity
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1167683551}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5cf472ac7b4534dd8a7bed1e3714204d, type: 3}
m_Name:
Expand Down
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## 0.0.33
*INCOMPLETE*
+ Fixed prediction embedding errors causing Unity build to fail.

## 0.0.32
+ Function can now make predictions fully offline after a predictor has been cached on-device.
Expand Down
1 change: 0 additions & 1 deletion Function.Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<Compile Include="Packages/ai.fxn.fxn3d/Editor/Build/macOSBuildHandler.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Editor/Build/AndroidBuildHandler.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Editor/Build/WindowsBuildHandler.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Editor/FunctionInfo.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Editor/FunctionSettingsProvider.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Editor/Build/LinuxBuildHandler.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Editor/FunctionProjectSettings.cs" />
Expand Down
1 change: 0 additions & 1 deletion Function.Unity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
<ItemGroup>
<Compile Include="Packages/ai.fxn.fxn3d/Unity/FunctionUnity.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Unity/Types/CachedPrediction.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Unity/Internal/FunctionInfo.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Unity/API/PredictionCacheClient.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Unity/Internal/FunctionSettings.cs" />
<Compile Include="Packages/ai.fxn.fxn3d/Unity/API/UnityClient.cs" />
Expand Down
31 changes: 21 additions & 10 deletions Packages/ai.fxn.fxn3d/Editor/Build/AndroidBuildHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Editor.Build {
Expand Down Expand Up @@ -51,7 +51,10 @@ protected override FunctionSettings CreateSettings (BuildReport report) {
)).Result;
return new CachedPrediction(prediction, clientId);
} catch (Exception ex) {
Debug.LogWarning($"Function: Failed to embed {tag} with error: {ex.Message}. Edge predictions with this predictor will likely fail at runtime.");
Debug.LogException(new InvalidOperationException(
$"Function: Failed to embed {tag} predictor. Predictions with this predictor will likely fail at runtime.",
ex
));
return null;
}
}));
Expand All @@ -75,14 +78,22 @@ void IPostGenerateGradleAndroidProject.OnPostGenerateGradleAndroidProject (strin
continue;
// Fetch resources
var client = new DotNetClient(Function.URL);
var resources = prediction.resources.Where(res => res.type == @"dso");
foreach (var resource in resources) {
var baseName = Path.GetFileName(PredictionService.GetResourcePath(resource, libDir));
var libName = $"lib{baseName}.so";
var path = Path.Combine(libDir, libName);
using var dsoStream = Task.Run(async () => await client.Download(resource.url)).Result;
using var fileStream = File.Create(path);
dsoStream.CopyTo(fileStream);
foreach (var resource in prediction.resources) {
try {
if (resource.type != @"dso")
continue;
var baseName = Path.GetFileName(PredictionService.GetResourcePath(resource, libDir));
var libName = $"lib{baseName}.so";
var path = Path.Combine(libDir, libName);
using var dsoStream = Task.Run(() => client.Download(resource.url)).Result;
using var fileStream = File.Create(path);
dsoStream.CopyTo(fileStream);
} catch (AggregateException ex) {
Debug.LogException(new InvalidOperationException(
$"Function: Failed to embed prediction resource for {prediction.tag} predictor. Predictions with this predictor will likely fail at runtime.",
ex.InnerException
));
}
}
}
cache = null;
Expand Down
2 changes: 1 addition & 1 deletion Packages/ai.fxn.fxn3d/Editor/Build/BuildHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

#nullable enable
Expand Down
2 changes: 1 addition & 1 deletion Packages/ai.fxn.fxn3d/Editor/Build/LinuxBuildHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Editor.Build {
Expand Down
2 changes: 1 addition & 1 deletion Packages/ai.fxn.fxn3d/Editor/Build/WebGLBuildHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

#nullable enable
Expand Down
2 changes: 1 addition & 1 deletion Packages/ai.fxn.fxn3d/Editor/Build/WindowsBuildHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Editor.Build {
Expand Down
32 changes: 21 additions & 11 deletions Packages/ai.fxn.fxn3d/Editor/Build/iOSBuildHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Editor.Build {
Expand Down Expand Up @@ -50,7 +50,10 @@ protected override FunctionSettings CreateSettings (BuildReport report) {
var cached = new CachedPrediction(prediction, ClientId);
return cached;
} catch (Exception ex) {
Debug.LogWarning($"Function: Failed to embed {tag} with error: {ex.Message}. Edge predictions with this predictor will likely fail at runtime.");
Debug.LogException(new InvalidOperationException(
$"Function: Failed to embed {tag} predictor. Predictions with this predictor will likely fail at runtime.",
ex
));
return null;
}
})
Expand All @@ -74,16 +77,23 @@ void IPostprocessBuildWithReport.OnPostprocessBuild (BuildReport report) {
var frameworks = new List<string>();
foreach (var prediction in cache)
foreach (var resource in prediction.resources) {
if (resource.type != @"dso")
continue;
var dsoPath = Path.GetTempFileName();
{
using var dsoStream = Task.Run(async () => await client.Download(resource.url)).Result;
using var fileStream = File.Create(dsoPath);
dsoStream.CopyTo(fileStream);
try {
if (resource.type != @"dso")
continue;
var dsoPath = Path.GetTempFileName();
{
using var dsoStream = Task.Run(() => client.Download(resource.url)).Result;
using var fileStream = File.Create(dsoPath);
dsoStream.CopyTo(fileStream);
}
ZipFile.ExtractToDirectory(dsoPath, frameworkDir, true);
frameworks.Add(resource.name);
} catch (AggregateException ex) {
Debug.LogException(new InvalidOperationException(
$"Function: Failed to embed prediction resource for {prediction.tag} predictor. Predictions with this predictor will likely fail at runtime.",
ex.InnerException
));
}
ZipFile.ExtractToDirectory(dsoPath, frameworkDir, true);
frameworks.Add(resource.name);
}
#if UNITY_IOS
var pbxPath = PBXProject.GetPBXProjectPath(report.summary.outputPath);
Expand Down
72 changes: 42 additions & 30 deletions Packages/ai.fxn.fxn3d/Editor/Build/macOSBuildHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Editor.Build {
Expand Down Expand Up @@ -56,7 +56,10 @@ protected override FunctionSettings CreateSettings (BuildReport report) {
var cached = new CachedPrediction(prediction, clientId);
return cached;
} catch (Exception ex) {
Debug.LogWarning($"Function: Failed to embed {tag} with error: {ex.Message}. Edge predictions with this predictor will likely fail at runtime.");
Debug.LogException(new InvalidOperationException(
$"Function: Failed to embed {tag} predictor. Predictions with this predictor will likely fail at runtime.",
ex
));
return null;
}
})
Expand Down Expand Up @@ -88,37 +91,46 @@ void IPostprocessBuildWithReport.OnPostprocessBuild (BuildReport report) {
// Embed
var frameworks = new List<string>();
var client = new DotNetClient(Function.URL);
foreach (var prediction in cache) {
var dso = prediction.resources.First(res => res.type == @"dso");
var dsoName = Path.GetFileName(PredictionService.GetResourcePath(dso, outputPath));
var dsoPath = Path.Combine(frameworkDir, dsoName);
using var dsoStream = Task.Run(async () => await client.Download(dso.url)).Result;
using var fileStream = File.Create(dsoPath);
dsoStream.CopyTo(fileStream);
frameworks.Add(dsoName);
}
foreach (var prediction in cache)
foreach (var resource in prediction.resources) {
try {
if (resource.type != @"dso")
continue;
var dsoName = Path.GetFileName(PredictionService.GetResourcePath(resource, outputPath));
var dsoPath = Path.Combine(frameworkDir, dsoName);
using var dsoStream = Task.Run(() => client.Download(resource.url)).Result;
using var fileStream = File.Create(dsoPath);
dsoStream.CopyTo(fileStream);
frameworks.Add(dsoName);
} catch (AggregateException ex) {
Debug.LogException(new InvalidOperationException(
$"Function: Failed to embed prediction resource for {prediction.tag} predictor. Predictions with this predictor will likely fail at runtime.",
ex.InnerException
));
}
}
// Check Xcode project
if (isApp)
return;
#if UNITY_STANDALONE_OSX
// Load Xcode project
var projectName = new DirectoryInfo(outputPath).Name + ".xcodeproj";
var pbxPath = Path.Combine(outputPath, projectName, @"project.pbxproj");
var project = new PBXProject();
project.ReadFromFile(pbxPath);
// Add frameworks
var targetGuid = project.GetUnityMainTargetGuid();
foreach (var framework in frameworks) {
var frameworkGuid = project.AddFile(
$"{Application.productName}/Frameworks/Function/" + framework,
"Frameworks/" + framework,
PBXSourceTree.Source
);
project.AddFileToEmbedFrameworks(targetGuid, frameworkGuid);
}
// Write
project.WriteToFile(pbxPath);
#endif
#if UNITY_STANDALONE_OSX
// Load Xcode project
var projectName = new DirectoryInfo(outputPath).Name + ".xcodeproj";
var pbxPath = Path.Combine(outputPath, projectName, @"project.pbxproj");
var project = new PBXProject();
project.ReadFromFile(pbxPath);
// Add frameworks
var targetGuid = project.GetUnityMainTargetGuid();
foreach (var framework in frameworks) {
var frameworkGuid = project.AddFile(
$"{Application.productName}/Frameworks/Function/" + framework,
"Frameworks/" + framework,
PBXSourceTree.Source
);
project.AddFileToEmbedFrameworks(targetGuid, frameworkGuid);
}
// Write
project.WriteToFile(pbxPath);
#endif
// Empty cache
cache = null;
}
Expand Down
18 changes: 0 additions & 18 deletions Packages/ai.fxn.fxn3d/Editor/FunctionInfo.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Packages/ai.fxn.fxn3d/Editor/FunctionInfo.cs.meta

This file was deleted.

4 changes: 1 addition & 3 deletions Packages/ai.fxn.fxn3d/Editor/FunctionMenu.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/*
* Function
* Copyright © 2024 NatML Inc. All rights reserved.
* Copyright © 2025 NatML Inc. All rights reserved.
*/

namespace Function.Editor {

using System.IO;
using UnityEditor;
using UnityEngine;

internal static class FunctionMenu {

Expand Down
Loading

0 comments on commit 758715a

Please sign in to comment.