Skip to content

Commit

Permalink
Added Unity WebGL sub-packages (#3)
Browse files Browse the repository at this point in the history
* feat: Initial version of the WebGL packages
* feat(ci): Yamato CI scripts
* feat: Unit test that sanity checks the native library file sizes
  • Loading branch information
atteneder authored and GitHub Enterprise committed Nov 2, 2023
1 parent a4ee405 commit 8870e23
Show file tree
Hide file tree
Showing 119 changed files with 2,797 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .yamato/environments.metafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
log_path: "test_results~"

artifactory_url: "https://artifactory.prd.cds.internal.unity3d.com/artifactory"
homebrew_url: "git@github.cds.internal.unity3d.com:unity/homebrew-unity.git"

sonarqube_ci:
url: "https://sonarqube.internal.unity3d.com"
dependency:
name: "com.unity.ide.rider"
version: "3.0.13"
analysis:
- pr
- branch

generic_project_path: .yamato/common/test_project~
player_path: build/player

npm_registry: "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
upm_ci_registry: "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm"

ci:
win:
env_sonar_token: "!SONARQUBE_PROD_ACCESS_TOKEN!"
env_unity_path: "%UNITY_EDITOR_PATH%"
env_yamato_src_dir: "%YAMATO_SOURCE_DIR%"
tool_utr: "utr.bat"
android:
env_sonar_token: "!SONARQUBE_PROD_ACCESS_TOKEN!"
env_unity_path: "%UNITY_EDITOR_PATH%"
env_yamato_src_dir: "%YAMATO_SOURCE_DIR%"
tool_utr: "utr.bat"
mac:
env_sonar_token: "$SONARQUBE_PROD_ACCESS_TOKEN"
env_unity_path: "$UNITY_EDITOR_PATH"
env_yamato_src_dir: "$YAMATO_SOURCE_DIR"
tool_utr: "./utr"

editor_component:
android:
args: "-c Android"
ios:
args: "-c iOS"

build_and_run: [ build, run ]
31 changes: 31 additions & 0 deletions .yamato/project.metafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
is_monorepo: !!bool true
enable_nightly: !!bool true
using_submodule: !!bool false
git_main_branch: main

enable_codecov: !!bool false
enable_sonarqube: !!bool true

upm_test_platforms:
- name: win
type: Unity::VM
flavor: b1.large
image: package-ci/win10:v4
- name: mac
type: Unity::VM::osx
image: package-ci/macos-13:v4
flavor: m1.mac

web_packages:
- name: 2020
emscripten_version: 1.38.48-fastcomp
unity_version: 2020.1
- name: 2021
emscripten_version: 2.0.19
unity_version: 2021.2
- name: 2022
emscripten_version: 3.1.8
unity_version: 2022.2
- name: 2023
emscripten_version: 3.1.38
unity_version: 2023.2
166 changes: 166 additions & 0 deletions .yamato/upm-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{% metadata_file .yamato/environments.metafile %}
{% metadata_file .yamato/project.metafile %}
---
{% for pkg in web_packages -%}
{% assign emscripten_version_suffix = pkg.emscripten_version | split: "-" | last %}
emscripten_{{pkg.name}}:
name: "Emscripten {{ pkg.name }}"
agent:
type: Unity::VM
image: package-ci/ubuntu-22.04:v4
flavor: b1.small
commands:

# TODO: Remove fastcomp support once 2020 is dropped
{% if emscripten_version_suffix == "fastcomp" %}
## Fastcomp requires legacy version (tag 3.1.29 or sooner; Unity fork latest synced tag is 2.0.18)
- git clone -b 2.0.18 --single-branch https://github.com/Unity-Technologies/emsdk.git
{% else %}
# Clone Emscripten
- git clone -b 3.1.38-unity --single-branch https://github.com/Unity-Technologies/emsdk.git
{% endif %}

# Install and activate correct Emscripten version
- |
pushd emsdk
./emsdk install {{ pkg.emscripten_version }}
./emsdk activate {{ pkg.emscripten_version }}
popd
# Configure
{% if emscripten_version_suffix == "fastcomp" %}
- |
source ./emsdk/emsdk_env.sh
emcmake cmake . -B build_web -DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1 -DCMAKE_BUILD_TYPE=MinSizeRel -DDRACO_JS_GLUE=OFF -DDRACO_UNITY_PLUGIN=ON -DDRACO_GLTF_BITSTREAM=ON -DDRACO_BACKWARDS_COMPATIBILITY=OFF
{% else %}
- |
source ./emsdk/emsdk_env.sh
EMSCRIPTEN="$EMSDK/upstream/emscripten" emcmake cmake . -B build_web -DCMAKE_BUILD_TYPE=MinSizeRel -DDRACO_JS_GLUE=OFF -DDRACO_UNITY_PLUGIN=ON -DDRACO_GLTF_BITSTREAM=ON -DDRACO_BACKWARDS_COMPATIBILITY=OFF
{% endif %}

# Build
- |
source ./emsdk/emsdk_env.sh
cmake --build build_web --target draco_unity
# Create and fill results folder
- |
mkdir -p wasm-binaries~/{{ pkg.name }}
mv build_web/libdraco_unity.* wasm-binaries~/{{ pkg.name }}
artifacts:
wasm-binaries:
paths:
- "wasm-binaries~/**/*"
{% endfor -%}

{% for pkg in web_packages -%}
upm_ci_pack_{{pkg.name}}:
name: "Pack {{ pkg.name }}"
agent:
type: Unity::VM
image: package-ci/ubuntu-22.04:v4
flavor: b1.small
commands:
# Install upm-ci
- npm install upm-ci-utils@stable -g --registry {{upm_ci_registry}}

# Move binaries into package
- mv wasm-binaries~/{{ pkg.name }}/lib*.* UnityPackages/com.unity.cloud.draco.webgl-{{ pkg.name }}/Runtime/Plugins/WebGL

# Pack
- upm-ci package pack --package-path "UnityPackages/com.unity.cloud.draco.webgl-{{ pkg.name }}"
dependencies:
- .yamato/upm-ci.yml#emscripten_{{pkg.name}}
artifacts:
packages:
paths:
- "upm-ci~/packages/**/*"
{% endfor -%}

{% for pkg in web_packages -%}
{% for platform in upm_test_platforms -%}
upm_ci_test_{{pkg.name}}_{{pkg.unity_version}}_{{platform.name}}:
name : "Test Editor {{pkg.name}} ({{ pkg.unity_version }}) on {{ platform.name }}"
agent:
type: {{platform.type}}
image: {{platform.image}}
flavor: {{platform.flavor}}
commands:
- npm install upm-ci-utils@stable -g --registry {{upm_ci_registry}}
- upm-ci package test --package-path "UnityPackages/com.unity.cloud.draco.webgl-{{ pkg.name }}" -u {{pkg.unity_version}} --type isolation-tests --enable-load-and-test-isolation
artifacts:
packages:
paths:
- "upm-ci~/packages/**/*"
logs:
paths:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/upm-ci.yml#upm_ci_pack_{{pkg.name}}
{% endfor -%}
{% endfor -%}

{% for pkg in web_packages -%}
upm_ci_publish_dry_run_{{pkg.name}}:
name: "Dry Run Publish {{ pkg.name }}"
agent:
type: Unity::VM
image: package-ci/win10:v4
flavor: b1.small
commands:
- npm install upm-ci-utils@stable -g --registry {{ upm_ci_registry }}
# going for dry run until we're ready to do a real publish
- upm-ci package publish --package-path "UnityPackages/com.unity.cloud.draco.webgl-{{ pkg.name }}" --dry-run
dependencies:
{% for platform in upm_test_platforms -%}
- .yamato/upm-ci.yml#upm_ci_test_{{pkg.name}}_{{pkg.unity_version}}_{{platform.name}}
{% endfor -%}
artifacts:
logs_{{pkg.name}}:
paths:
- "{{ log_path }}/**/*"
package:
paths:
- "upm-ci~/packages/*.tgz"
{% endfor -%}


upm_ci_publish_dry_run:
name: "Dry Run Publish"
dependencies:
{% for pkg in web_packages -%}
- .yamato/upm-ci.yml#upm_ci_publish_dry_run_{{pkg.name}}
{% endfor -%}


{% for pkg in web_packages -%}
upm_ci_publish_{{pkg.name}}:
name: "Publish to Internal Registry {{ pkg.name }}"
agent:
type: Unity::VM
image: package-ci/win10:v4
flavor: b1.small
commands:
- npm install upm-ci-utils@stable -g --registry {{ upm_ci_registry }}
# going for dry run until we're ready to do a real publish
- upm-ci package publish --package-path "UnityPackages/com.unity.cloud.draco.webgl-{{ pkg.name }}"
dependencies:
{% for platform in upm_test_platforms -%}
- .yamato/upm-ci.yml#upm_ci_test_{{pkg.name}}_{{pkg.unity_version}}_{{platform.name}}
{% endfor -%}
artifacts:
logs_{{pkg.name}}:
paths:
- "{{ log_path }}/**/*"
package:
paths:
- "upm-ci~/packages/*.tgz"
{% endfor -%}

upm_ci_publish:
name: "Publish to Internal Registry"
dependencies:
{% for pkg in web_packages -%}
- .yamato/upm-ci.yml#upm_ci_publish_{{pkg.name}}
{% endfor -%}
8 changes: 8 additions & 0 deletions UnityPackages/com.unity.cloud.draco.webgl-2020/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
Initial sub package publication

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
uid: api-index
---

# Draco for Unity WebGL Sub-Package API Documentation

This package does not provide any public API. Instead please consult the documentation of its main package [Draco for Unity][DracoForUnity].

## Trademarks

*Unity®* is a registered trademark of [Unity Technologies][Unity].

*Draco™* is a trademark of [*Google LLC*][GoogleLLC].

[DracoForUnity]: https://docs.unity3d.com/Packages/com.unity.cloud.draco@latest
[GoogleLLC]: https://about.google/
[unity]: https://unity.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Draco for Unity WebGL Sub-Package Documentation

This package contains a Unity® version specific WebGL native library of Draco™ (in the form of pre-compiled, binary [WebAssembly][wasm]).

By itself it provides no functionality and should not get installed manually. It is a sub-package of its main package [Draco for Unity][DracoForUnity], which will install it automatically. If the main package is removed, this sub-package will remove itself automatically as well.

## Trademarks

*Unity®* is a registered trademark of [Unity Technologies][Unity].

*Draco™* is a trademark of [*Google LLC*][GoogleLLC].

[DracoForUnity]: https://docs.unity3d.com/Packages/com.unity.cloud.draco@latest
[GoogleLLC]: https://about.google/
[unity]: https://unity.com
[wasm]: https://webassembly.org/
8 changes: 8 additions & 0 deletions UnityPackages/com.unity.cloud.draco.webgl-2020/Editor.meta

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Draco.Webgl-2020.Editor",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Threading.Tasks;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEngine;
using UnityEngine.Assertions;
using System.Linq;

namespace SubPackage
{
static class SubPackageCleanup
{

const string k_Name = "com.unity.cloud.draco.webgl-2020";
const string k_DisplayName = "Draco for Unity WebGL 2020";

static readonly string[] k_MainPackageNames = {
"com.unity.cloud.draco",
"com.atteneder.draco"
};

#if !DISABLE_SUB_PACKAGE_CHECK
[InitializeOnLoadMethod]
#endif
static async void InitializeOnLoad()
{
var request = Client.List(offlineMode: true, includeIndirectDependencies: false);

while (!request.IsCompleted)
await Task.Yield();

Assert.AreEqual(StatusCode.Success, request.Status);

var mainPackageInManifest = request.Result.Select(package => package.name).Intersect(k_MainPackageNames).Any();

if (!mainPackageInManifest)
{
Debug.LogWarning($"Package {k_DisplayName} ({k_Name}) is missing its main package <a href=\"https://docs.unity3d.com/Packages/com.unity.cloud.draco@latest/\">Draco for Unity</a> and should get removed.");
}
}
}
}

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

Loading

0 comments on commit 8870e23

Please sign in to comment.