Skip to content

Commit

Permalink
Merge pull request #487 from CesiumGS/vcpkg-swl
Browse files Browse the repository at this point in the history
Build and CI improvements, building on vcpkg
  • Loading branch information
kring authored Aug 14, 2024
2 parents e819812 + 0402763 commit 1a09665
Show file tree
Hide file tree
Showing 20 changed files with 929 additions and 896 deletions.
40 changes: 26 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ jobs:
del ./UnityHubSetup.exe
- name: Install Unity
run: |
Start-Process -FilePath "C:/Program Files/Unity Hub/Unity Hub.exe" -Args "-- --headless install --version 2021.3.13f1 --changeset 9e7d58001ecf" -Wait
Start-Process -FilePath "C:/Program Files/Unity Hub/Unity Hub.exe" -Args "-- --headless install-modules --version 2021.3.13f1 --changeset 9e7d58001ecf --module android android-sdk-ndk-tools android-open-jdk-8u172-b11 universal-windows-platform uwp-il2cpp" -Wait
Start-Process -FilePath "C:/Program Files/Unity Hub/Unity Hub.exe" -Args "-- --headless install --version 2022.3.41f1 --changeset 0f988161febf" -Wait
Start-Process -FilePath "C:/Program Files/Unity Hub/Unity Hub.exe" -Args "-- --headless install-modules --version 2022.3.41f1 --changeset 0f988161febf --module android android-sdk-ndk-tools android-open-jdk-11.0.14.1+1 universal-windows-platform" -Wait
- name: Create SSH tunnel to Unity License Server
env:
UNITY_LICENSE_SERVER_SSH_KEY: ${{ secrets.UNITY_LICENSE_SERVER_SSH_KEY }}
Expand Down Expand Up @@ -103,6 +103,10 @@ jobs:
run: |
mkdir -p d:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity
mv $ENV:GITHUB_WORKSPACE/* d:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity
# Disable Unity audio
mkdir -p d:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity\ProjectSettings
$text="%YAML 1.1`n%TAG !u! tag:unity3d.com,2011:`n--- !u!11 &1`nAudioManager:`n m_DisableAudio: 1`n"
[IO.File]::WriteAllLines("d:/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/ProjectSettings/AudioManager.asset",$text)
- name: Build Reinterop
run: |
cd d:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity
Expand All @@ -121,7 +125,12 @@ jobs:
$ENV:EZVCPKG_BASEDIR="D:/.ezvcpkg"
# Run the build
dotnet run --project Build~
cat D:\cesium\CesiumForUnityBuildProject\Packages\com.cesium.unity\native~\build-Android-arm64\build.log
- name: Publish Logs
if: success() || failure() # run this step even if previous step failed
uses: actions/upload-artifact@v4
with:
name: Native Build Logs - Windows
path: d:/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-*/build.log
- name: Publish package artifact
if: ${{ success() }}
uses: actions/upload-artifact@v4
Expand All @@ -130,7 +139,7 @@ jobs:
path: d:\cesium\CesiumForUnityBuildProject\*.tgz
- name: Run Tests
run: |
start -FilePath "C:\Program Files\Unity\Hub\Editor\2021.3.13f1\Editor\Unity.exe" -ArgumentList "-runTests -batchmode -projectPath d:\cesium\CesiumForUnityBuildProject -testResults d:\cesium\temp\TestResults.xml -testPlatform PlayMode -logFile d:\cesium\temp\test-log.txt" -Wait
start -FilePath "C:\Program Files\Unity\Hub\Editor\2022.3.41f1\Editor\Unity.exe" -ArgumentList "-runTests -batchmode -projectPath d:\cesium\CesiumForUnityBuildProject -testResults d:\cesium\temp\TestResults.xml -testPlatform PlayMode -logFile d:\cesium\temp\test-log.txt" -Wait
cat d:\cesium\temp\test-log.txt
- name: Test Report
uses: kring/[email protected]
Expand Down Expand Up @@ -166,14 +175,14 @@ jobs:
sudo cp -R "./UnityHubSetup/Unity Hub.app" /Applications
hdiutil detach ./UnityHubSetup
rm ./UnityHubSetup.dmg
- name: Install Unity 2021.3.13f1
- name: Install Unity 2022.3.41f1
# This command sometimes returns exit code 130, despite actually succeeding.
continue-on-error: true
run: |
/Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install --version 2021.3.13f1 --changeset 9e7d58001ecf --architecture x86_64
/Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install --version 2022.3.41f1 --changeset 0f988161febf --architecture arm64
- name: Install Unity iOS Support
run: |
/Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install-modules --version 2021.3.13f1 --changeset 9e7d58001ecf --module ios --architecture x86_64
/Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless install-modules --version 2022.3.41f1 --changeset 0f988161febf --module ios --architecture arm64
- name: Configure Unity to Use the License Server
run: |
sudo mkdir -p "/Library/Application Support/Unity/config"
Expand Down Expand Up @@ -213,6 +222,9 @@ jobs:
run: |
mkdir -p ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity
mv $GITHUB_WORKSPACE/* ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity
# Disable Unity audio
mkdir -p ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/ProjectSettings
echo '%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!11 &1\nAudioManager:\n m_DisableAudio: 1\n' > ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/ProjectSettings/AudioManager.asset
- name: Build Reinterop
run: |
cd ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity
Expand All @@ -224,12 +236,12 @@ jobs:
cd ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity
dotnet run --project Build~
ls -l ~/cesium/CesiumForUnityBuildProject
- name: Print log
if: ${{ failure() }}
run: |
cat /Users/runner/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-Standalone-x86_64/build.log
cat /Users/runner/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-Standalone-arm64/build.log
cat /Users/runner/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-iOS/build.log
- name: Publish Logs
if: success() || failure() # run this step even if previous step failed
uses: actions/upload-artifact@v4
with:
name: Native Build Logs - macOS
path: ~/cesium/CesiumForUnityBuildProject/Packages/com.cesium.unity/native~/build-*/build.log
- name: Publish package artifact
if: ${{ success() }}
uses: actions/upload-artifact@v4
Expand All @@ -238,7 +250,7 @@ jobs:
path: ~/cesium/CesiumForUnityBuildProject/*.tgz
- name: Run Tests
run: |
/Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/MacOS/Unity -runTests -batchmode -projectPath ~/cesium/CesiumForUnityBuildProject -testResults ~/cesium/CesiumForUnityBuildProject/TestResults.xml -testPlatform PlayMode -logFile ~/cesium/CesiumForUnityBuildProject/test-log.txt
/Applications/Unity/Hub/Editor/2022.3.41f1/Unity.app/Contents/MacOS/Unity -runTests -batchmode -projectPath ~/cesium/CesiumForUnityBuildProject -testResults ~/cesium/CesiumForUnityBuildProject/TestResults.xml -testPlatform PlayMode -logFile ~/cesium/CesiumForUnityBuildProject/test-log.txt
cat ~/cesium/CesiumForUnityBuildProject/test-log.txt
ls /Users/runner/cesium/CesiumForUnityBuildProject/TestResults.xml
- name: Test Report
Expand Down
6 changes: 5 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
url = https://github.com/htacg/tidy-html5.git
[submodule "native~/extern/enum-flags"]
path = native~/extern/enum-flags
url = https://github.com/grisumbras/enum-flags.git
url = https://github.com/kring/enum-flags.git
[submodule "native~/extern/swl-variant"]
path = native~/extern/swl-variant
url = https://github.com/kring/swl-variant.git
branch = exception-public-inheritance
33 changes: 27 additions & 6 deletions Build~/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ public void Run()
Directory.CreateDirectory(outputPackagePath);

Console.WriteLine("**** Modifying the csc.rsp files to write generated files to disk");
string generatedRuntimePath = Path.Combine(tempPath, "generated", "Runtime");
Directory.CreateDirectory(generatedRuntimePath);
string generatedEditorPath = Path.Combine(tempPath, "generated", "Editor");
Directory.CreateDirectory(generatedEditorPath);
string generatedRuntimeBasePath = Path.Combine(tempPath, "generated", "Runtime");
Directory.CreateDirectory(generatedRuntimeBasePath);
string generatedEditorBasePath = Path.Combine(tempPath, "generated", "Editor");
Directory.CreateDirectory(generatedEditorBasePath);

File.AppendAllText(runtimeCscRspPath, "-generatedfilesout:\"" + generatedRuntimePath + "\"" + Environment.NewLine, Encoding.UTF8);
File.AppendAllText(editorCscRspPath, "-generatedfilesout:\"" + generatedEditorPath + "\"" + Environment.NewLine, Encoding.UTF8);
File.AppendAllText(runtimeCscRspPath, "-generatedfilesout:\"" + generatedRuntimeBasePath + "\"" + Environment.NewLine, Encoding.UTF8);
File.AppendAllText(editorCscRspPath, "-generatedfilesout:\"" + generatedEditorBasePath + "\"" + Environment.NewLine, Encoding.UTF8);

string generatedRuntimePath = Path.Combine(generatedRuntimeBasePath, "Reinterop");
string generatedEditorPath = Path.Combine(generatedEditorBasePath, "Reinterop");

string sceneDirectory = Path.Combine(Utility.ProjectRoot, "Assets", "Scenes");
Directory.CreateDirectory(sceneDirectory);
Expand All @@ -57,6 +60,24 @@ public void Run()
}
}

// Disable Unity audio, because we don't need it and because it seems to take 10-20 minutes
// to time out on macOS on GitHub Actions every time we start up Unity.
string projectSettingsDirectory = Path.Combine(Utility.ProjectRoot, "ProjectSettings");
Directory.CreateDirectory(projectSettingsDirectory);
string audioManagerPath = Path.Combine(projectSettingsDirectory, "AudioManager.asset");
if (!File.Exists(audioManagerPath))
{
Console.WriteLine("**** Creating AudioManager.asset to disable Unity audio");
using (StreamWriter audioManager = new StreamWriter(audioManagerPath))
{
audioManager.WriteLine("%YAML 1.1");
audioManager.WriteLine("%TAG !u! tag:unity3d.com,2011:");
audioManager.WriteLine("--- !u!11 &1");
audioManager.WriteLine("AudioManager:");
audioManager.WriteLine(" m_DisableAudio: 1");
}
}

Console.WriteLine("**** Compiling C# code for the Editor");
unity.Run(new[]
{
Expand Down
5 changes: 4 additions & 1 deletion Editor/CompileCesiumForUnityNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ private static string GetDirectoryNameForPlatform(BuildTargetGroup platformGroup
return "Editor";
else if (IsIOS(platformGroup, platform))
return "iOS";
// Make sure we use "WSA" and not "Metro"
else if (platformGroup == BuildTargetGroup.WSA)
return "WSA";
return platformGroup.ToString();
}

Expand All @@ -440,7 +443,7 @@ internal static void BuildNativeLibrary(LibraryToBuild library)
string projectPath = Path.Combine(Application.dataPath, "..");
string logDisplayName = Path.GetRelativePath(projectPath, logFilename);

EditorUtility.DisplayProgressBar($"Building CesiumForUnityNative", $"See {logDisplayName}.", 0.0f);
EditorUtility.DisplayProgressBar($"Building CesiumForUnityNative: {Path.GetFileName(library.BuildDirectory)}", $"See {logDisplayName}.", 0.0f);

using (StreamWriter log = new StreamWriter(logFilename, false, Encoding.UTF8))
{
Expand Down
5 changes: 3 additions & 2 deletions Runtime/CesiumFlyToController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ private void Reset()
private bool DetectMovementInput()
{
double3 currentPositionECEF = this._globeAnchor.positionGlobeFixed;
bool3 positionEquality = currentPositionECEF == this._previousPositionECEF;
return !positionEquality.x || !positionEquality.y || !positionEquality.z;
double distanceSquared = math.lengthsq(currentPositionECEF - this._previousPositionECEF);
const double distanceConsideredMovement = 1e-6; // 1/1000 of a millimeter
return distanceSquared >= (distanceConsideredMovement * distanceConsideredMovement);
}

/// <summary>
Expand Down
59 changes: 59 additions & 0 deletions Tests/TestCesiumFlyToController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,63 @@ public IEnumerator FlyToLocationLongitudeLatitudeHeight()
Assert.That(goFlyer.transform.position.y, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));
Assert.That(goFlyer.transform.position.z, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));
}

[UnityTest]
public IEnumerator FlyToLocationLongitudeLatitudeHeightInterrupted()
{
GameObject goGeoreference = new GameObject("Georeference");
CesiumGeoreference georeference = goGeoreference.AddComponent<CesiumGeoreference>();
georeference.longitude = -55.0;
georeference.latitude = 55.0;
georeference.height = 1000.0;

GameObject goFlyer = new GameObject("Flyer");
goFlyer.transform.parent = goGeoreference.transform;

CesiumGlobeAnchor anchor = goFlyer.AddComponent<CesiumGlobeAnchor>();
goFlyer.AddComponent<CesiumOriginShift>();
CesiumFlyToController flyToController = goFlyer.AddComponent<CesiumFlyToController>();

// Make the flight fast so the test doesn't take too long.
flyToController.flyToDuration = 0.25;

anchor.adjustOrientationForGlobeWhenMoving = false;
anchor.longitudeLatitudeHeight = new double3(20.0, -25.0, 1000.0);
anchor.adjustOrientationForGlobeWhenMoving = true;

yield return null;

// The origin should have been shifted so the flyer is at the origin.
Assert.That(goFlyer.transform.position.x, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));
Assert.That(goFlyer.transform.position.y, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));
Assert.That(goFlyer.transform.position.z, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));

// Start a flight to elsewhere
bool flightComplete = false;
flyToController.OnFlightComplete += () =>
{
flightComplete = true;
};

bool flightInterrupted = false;
flyToController.OnFlightInterrupted += () =>
{
flightInterrupted = true;
};

flyToController.FlyToLocationLongitudeLatitudeHeight(new double3(100.0, 25.0, 800.0), 0.0f, 0.0f, true);

yield return null;

Assert.IsFalse(flightComplete);
Assert.IsFalse(flightInterrupted);

// Give the object a new position, which should abort the flight.
goFlyer.transform.position = new Vector3(100.0f, 200.0f, 300.0f);

yield return null;

Assert.IsFalse(flightComplete);
Assert.IsTrue(flightInterrupted);
}
}
47 changes: 25 additions & 22 deletions Tests/TestCesiumGeoreference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ public IEnumerator ChangingOriginAtRuntimeUpdatesGlobeAnchors()

yield return null;

Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f));
IEqualityComparer<float> epsilon8f = new FloatEqualityComparer(1e-8f);
Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(0.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f).Using(epsilon8f));

georeference.SetOriginLongitudeLatitudeHeight(-55.1, 54.9, 1001.0);

Assert.That(goAnchored.transform.localPosition.x, Is.Not.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.y, Is.Not.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.z, Is.Not.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.x, Is.Not.EqualTo(0.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.y, Is.Not.EqualTo(0.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.z, Is.Not.EqualTo(0.0f).Using(epsilon8f));

yield return null;

Assert.That(goAnchored.transform.localPosition.x, Is.Not.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.y, Is.Not.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.z, Is.Not.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.x, Is.Not.EqualTo(0.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.y, Is.Not.EqualTo(0.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.z, Is.Not.EqualTo(0.0f).Using(epsilon8f));
}

[UnityTest]
Expand All @@ -56,9 +57,10 @@ public IEnumerator ChangingParentTransformAndGeoreferenceMaintainsCorrectGlobePo

yield return null;

Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(0.0f));
Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f));
IEqualityComparer<float> epsilon8f = new FloatEqualityComparer(1e-8f);
Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(0.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f).Using(epsilon8f));

// Change both the origin and the transform.
georeference.transform.localPosition = new Vector3(100.0f, 200.0f, 300.0f);
Expand All @@ -74,10 +76,10 @@ public IEnumerator ChangingParentTransformAndGeoreferenceMaintainsCorrectGlobePo

// Its local local position should be affected by the georeference origin change
// but not by the parent transform change.
IEqualityComparer<float> epsilon4 = new FloatEqualityComparer(1e-3f);
Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f).Using(epsilon4));
Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(-1000.0f).Using(epsilon4));
Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f).Using(epsilon4));
IEqualityComparer<float> epsilon3 = new FloatEqualityComparer(1e-3f);
Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(0.0f).Using(epsilon3));
Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(-1000.0f).Using(epsilon3));
Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(0.0f).Using(epsilon3));
}

[UnityTest]
Expand All @@ -97,13 +99,14 @@ public IEnumerator GeoreferenceScaleAffectsGlobeAnchors()

yield return null;

Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(1.0f));
Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(2.0f));
Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(3.0f));
IEqualityComparer<float> epsilon8f = new FloatEqualityComparer(1e-8f);
Assert.That(goAnchored.transform.localPosition.x, Is.EqualTo(1.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.y, Is.EqualTo(2.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localPosition.z, Is.EqualTo(3.0f).Using(epsilon8f));

Assert.That(goAnchored.transform.localScale.x, Is.EqualTo(4.0f));
Assert.That(goAnchored.transform.localScale.y, Is.EqualTo(5.0f));
Assert.That(goAnchored.transform.localScale.z, Is.EqualTo(6.0f));
Assert.That(goAnchored.transform.localScale.x, Is.EqualTo(4.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localScale.y, Is.EqualTo(5.0f).Using(epsilon8f));
Assert.That(goAnchored.transform.localScale.z, Is.EqualTo(6.0f).Using(epsilon8f));

// The globe anchor's scale initially matches the local scale.
IEqualityComparer<double> epsilon8 = Comparers.Double(1e-8);
Expand Down
Loading

0 comments on commit 1a09665

Please sign in to comment.