Skip to content

Commit

Permalink
download adaptation layer
Browse files Browse the repository at this point in the history
add ios build
  • Loading branch information
leanmendoza committed Aug 29, 2023
1 parent f6acfc4 commit b99f0b6
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 90 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ This repos is set up to be opened with Visual Studio Code. In the section `Run a
## Run test with coverage
1. Ensure you are in `rust/xtask` folder first
2. Run `cargo run -- coverage --dev`. It'll create a `coverage` folder with the index.html with the all information. For running this commands you need to have lvvm tools and grcov, you can install them with `rustup component add llvm-tools-preview` and `cargo install grcov`.

# Mobile targets
See `rust/decentraland-godot-lib/builds.md`
2 changes: 2 additions & 0 deletions godot/decentraland_godot_lib.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ linux.release.x86_64 = "res://lib/libdecentraland_godot_lib.so"
macos.debug = "res://lib/libdecentraland_godot_lib.dylib"
macos.release = "res://lib/libdecentraland_godot_lib.dylib"
android.debug.arm64 = "res://lib/android/libdecentraland_godot_lib.so"
ios.debug.arm64 = "res://lib/ios/libdecentraland_godot_lib.dylib"
ios.release.arm64 = "res://lib/ios/libdecentraland_godot_lib.dylib"
77 changes: 73 additions & 4 deletions godot/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@ gradle_build/use_gradle_build=true
gradle_build/export_format=0
gradle_build/min_sdk=""
gradle_build/target_sdk=""
plugins/GodotOpenXRMeta=false
plugins/GodotOpenXRKHR=false
plugins/GodotOpenXRLynx=false
plugins/GodotOpenXRPico=false
architectures/armeabi-v7a=false
architectures/arm64-v8a=true
architectures/x86=false
Expand Down Expand Up @@ -408,3 +404,76 @@ permissions/write_sms=false
permissions/write_social_stream=false
permissions/write_sync_settings=false
permissions/write_user_dictionary=false

[preset.4]

name="iOS"
platform="iOS"
runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="*, *.*"
exclude_filter=""
export_path="../../../Documents/ios_project/Decentraland Mobile Client.ipa"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false

[preset.4.options]

custom_template/debug=""
custom_template/release=""
architectures/arm64=true
application/app_store_team_id="ST7KK6DJ5R"
application/code_sign_identity_debug=""
application/export_method_debug=1
application/code_sign_identity_release=""
application/export_method_release=0
application/targeted_device_family=2
application/bundle_identifier="com.decentraland.godot"
application/signature=""
application/short_version="1.0"
application/version="1.0"
application/icon_interpolation=4
application/launch_screens_interpolation=4
capabilities/access_wifi=false
capabilities/push_notifications=false
user_data/accessible_from_files_app=false
user_data/accessible_from_itunes_sharing=false
privacy/camera_usage_description=""
privacy/camera_usage_description_localized={}
privacy/microphone_usage_description=""
privacy/microphone_usage_description_localized={}
privacy/photolibrary_usage_description=""
privacy/photolibrary_usage_description_localized={}
icons/iphone_120x120=""
icons/iphone_180x180=""
icons/ipad_76x76=""
icons/ipad_152x152=""
icons/ipad_167x167=""
icons/app_store_1024x1024=""
icons/spotlight_40x40=""
icons/spotlight_80x80=""
icons/settings_58x58=""
icons/settings_87x87=""
icons/notification_40x40=""
icons/notification_60x60=""
storyboard/use_launch_screen_storyboard=false
storyboard/image_scale_mode=0
storyboard/custom_image@2x=""
storyboard/custom_image@3x=""
storyboard/use_custom_bg_color=false
storyboard/custom_bg_color=Color(0, 0, 0, 1)
landscape_launch_screens/iphone_2436x1125=""
landscape_launch_screens/iphone_2208x1242=""
landscape_launch_screens/ipad_1024x768=""
landscape_launch_screens/ipad_2048x1536=""
portrait_launch_screens/iphone_640x960=""
portrait_launch_screens/iphone_640x1136=""
portrait_launch_screens/iphone_750x1334=""
portrait_launch_screens/iphone_1125x2436=""
portrait_launch_screens/ipad_768x1024=""
portrait_launch_screens/ipad_1536x2048=""
portrait_launch_screens/iphone_1242x2208=""
2 changes: 1 addition & 1 deletion godot/src/global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Node

signal config_changed

@onready var is_mobile = OS.get_name() == "Android"
@onready var is_mobile = OS.get_name() == "Android" || OS.get_name() == "iOS"
#@onready var is_mobile = true

## Global classes (singleton pattern)
Expand Down
41 changes: 35 additions & 6 deletions godot/src/logic/parcel_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class_name ParcelManager

const MAIN_JS_FILE_REQUEST = 100
const MAIN_CRDT_FILE_REQUEST = 101
const ADAPTATION_LAYER_JS_FILE_REQUEST = 102

var adaptation_layer_js_request: int = -1
var adaptation_layer_js_local_path: String = "user://sdk-adaptation-layer.js"

var scene_runner: SceneManager = null
var realm: Realm = null
Expand All @@ -28,6 +32,9 @@ func _ready():
Global.config.param_changed.connect(self._on_config_changed)


if FileAccess.file_exists(adaptation_layer_js_local_path):
DirAccess.remove_absolute(adaptation_layer_js_local_path)

func _on_config_changed(param: ConfigData.ConfigParams):
if param == ConfigData.ConfigParams.SceneRadius:
scene_entity_coordinator.set_scene_radius(Global.config.scene_radius)
Expand Down Expand Up @@ -145,6 +152,8 @@ func _on_requested_completed(response: RequestResponse):
_on_main_js_file_requested_completed(response)
MAIN_CRDT_FILE_REQUEST:
_on_main_crdt_file_requested_completed(response)
ADAPTATION_LAYER_JS_FILE_REQUEST:
_on_adaptation_layer_js_file_requested_completed(response)
_:
pass

Expand Down Expand Up @@ -173,6 +182,15 @@ func _on_main_crdt_file_requested_completed(response: RequestResponse):
_on_try_spawn_scene(scene)


func _on_adaptation_layer_js_file_requested_completed(response: RequestResponse):
var request_id = response.id()
for scene in loaded_scenes.values():
var req = scene.get("req", {})
if req.get("js_request_id", -1) == request_id:
scene.req.js_request_completed = true
_on_try_spawn_scene(scene)


func _on_main_js_file_requested_completed(response: RequestResponse):
var scene = get_scene_by_req_id(response.id())

Expand Down Expand Up @@ -204,15 +222,13 @@ func load_scene(scene_entity_id: String, entity: Dictionary):
var local_main_js_path = ""
var js_request_completed = true

print("is_sdk7 ", is_sdk7)
if is_sdk7:
var main_js_file_hash = entity.get("content", {}).get(metadata.get("main", ""), null)
if main_js_file_hash == null:
printerr("Scene ", scene_entity_id, " fail getting the main js file hash.")
return false

local_main_js_path = "user://content/" + main_js_file_hash

if not FileAccess.file_exists(local_main_js_path) or main_js_file_hash.begins_with("b64"):
js_request_completed = false
var main_js_file_url: String = entity.baseUrl + main_js_file_hash
Expand All @@ -222,7 +238,16 @@ func load_scene(scene_entity_id: String, entity: Dictionary):
local_main_js_path.replace("user:/", OS.get_user_data_dir())
)
else:
local_main_js_path = "res://assets/sdk7-adaption-layer/index.js"
local_main_js_path = String(adaptation_layer_js_local_path)
if not FileAccess.file_exists(local_main_js_path):
js_request_completed = false
if adaptation_layer_js_request == -1:
adaptation_layer_js_request = http_requester._requester.request_file(
ADAPTATION_LAYER_JS_FILE_REQUEST,
"https://renderer-artifacts.decentraland.org/sdk7-adaption-layer/main/index.js",
local_main_js_path.replace("user:/", OS.get_user_data_dir())
)
main_js_request_id = adaptation_layer_js_request

var req = {
"js_request_completed": js_request_completed,
Expand All @@ -248,9 +273,13 @@ func load_scene(scene_entity_id: String, entity: Dictionary):

loaded_scenes[scene_entity_id]["req"] = req

if req.crdt_request_completed and req.js_request_completed:
_on_try_spawn_scene(loaded_scenes[scene_entity_id])

if is_sdk7:
if req.crdt_request_completed and req.js_request_completed:
_on_try_spawn_scene(loaded_scenes[scene_entity_id])
else:
# SDK6 scenes don't have crdt file, and if they'd have, there is no mechanism to make a clean spawn of both
if req.js_request_completed:
_on_try_spawn_scene(loaded_scenes[scene_entity_id])

func _on_try_spawn_scene(scene):
var local_main_js_path = scene.req.js_path
Expand Down
6 changes: 3 additions & 3 deletions godot/src/ui/explorer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ size = Vector2(4800, 4800)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_fstik"]
albedo_texture = ExtResource("2_7jksa")
uv1_scale = Vector3(300, 300, 300)
uv1_scale = Vector3(4800, 4800, 4800)
texture_filter = 0

[sub_resource type="Theme" id="Theme_1ufu0"]

[sub_resource type="ButtonGroup" id="ButtonGroup_fw5xg"]
[sub_resource type="ButtonGroup" id="ButtonGroup_v6d3l"]
resource_name = "Tabs"

[node name="explorer" type="Node3D"]
Expand Down Expand Up @@ -171,7 +171,7 @@ layout_mode = 2
[node name="Control_Menu" parent="UI" instance=ExtResource("5_mso44")]
visible = false
layout_mode = 1
group = SubResource("ButtonGroup_fw5xg")
group = SubResource("ButtonGroup_v6d3l")

[node name="Timer_BroadcastPosition" type="Timer" parent="."]
wait_time = 0.1
Expand Down
5 changes: 3 additions & 2 deletions rust/decentraland-godot-lib/android-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

# Tested with NDK 25.2.9519653
ANDROID_NDK=~/Android/Sdk/ndk/25.2.9519653
export FFMPEG_DIR=~/Documents/github/ffmpeg-kit/prebuilt/android-arm64/ffmpeg

# Run the specified commands
export TARGET_CC=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang
export TARGET_CXX=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang++
export TARGET_AR=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
export FFMPEG_DIR=~/Documents/github/ffmpeg-kit/prebuilt/android-arm64/ffmpeg
export RUSTY_V8_MIRROR=https://github.com/leanmendoza/rusty_v8/releases/download
export CARGO_FFMPEG_SYS_DISABLE_SIZE_T_IS_USIZE=1

Expand All @@ -23,4 +23,5 @@ sed -i "s|$ffmpeg_dep|$ffmpeg_dep_android|g" "$cargo_file_path"
# Revert Cargo.toml back to its original content
echo "$original_content" > $cargo_file_path

(cp target/aarch64-linux-android/release/libdecentraland_godot_lib.so ../../godot/lib/android/libdecentraland_godot_lib.so) || true
mkdir ../../godot/lib/android/ || true
cp target/aarch64-linux-android/release/libdecentraland_godot_lib.so ../../godot/lib/android/libdecentraland_godot_lib.so
43 changes: 43 additions & 0 deletions rust/decentraland-godot-lib/builds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

# Dependencies

Both android and iOS you need to clone ffmpeg-kit and build it.

## TODO
1. See what libraries from the kit should be compiled instead of using `--full`

## Android
TODO

## iOS
After cloning `ffmpeg-kit` ensure you have the right environment to build it. Some tips:
1. Install one-by-one the brew dependencies `autoconf automake libtool pkg-config curl git doxygen nasm cmake gcc gperf texinfo yasm bison autogen wget gettext meson ninja ragel groff gtk-doc-tools libtasn1`
2. Ensure you `bison` version in your path is > 2.4 (`bison --help`), probably you need to add the brew isntalled to PATH

The command to build it:
`bash ios.sh --full --disable-armv7 --disable-armv7s --disable-arm64-mac-catalyst --disable-arm64-simulator --disable-arm64e --disable-i386 --disable-x86-64 --disable-x86-64-mac-catalyst --disable-lib-fribidi --disable-lib-openssl --disable-lib-libass`
This only buils for arm64. `fribidi` and `libass` should be compiled but I got errors when I tried to include them.


# Build

## iOS

1. Once the build is done, you need to modify the `ios-build.sh` the line:
- `export FFMPEG_DIR=$FFMPEG_FOLDER/prebuilt/apple-ios-arm64/ffmpeg`
- Replace $FFMPEG_FOLDER with your path where you clone ffmpeg_kit

2. Open godot (see the README.md on the root folder of this repo) and make an export of iOS. TeamID is required to export it.

3. Open the project generated with XCode and add the ffmpeg libraries:
- Copy all the `.framework` folders of the $FFMPEG_FOLDER/prebuilt/bundle-apple-framework-ios to the folder generated by Godot
- Go to the Project view, and go to File>Add file, select all the .frameworks and add them.
- Select the app target and then the General tab
- Scroll down to the "Framework, Libraries, and Embedded Content" section.
- Make sure your framework is "Embed & Sign".

## Android

1. Once the build is done, you need to modify the `android-build.sh` the line:
- `export FFMPEG_DIR=$FFMPEG_FOLDER/prebuilt/apple-ios-arm64/ffmpeg`
- Replace $FFMPEG_FOLDER with your path where you clone ffmpeg_kit
9 changes: 9 additions & 0 deletions rust/decentraland-godot-lib/ios-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

export FFMPEG_DIR=~/github/ffmpeg-kit/prebuilt/apple-ios-arm64/ffmpeg
export RUSTY_V8_MIRROR=https://github.com/leanmendoza/rusty_v8/releases/download

GN_ARGS=use_custom_libcxx=false RUST_BACKTRACE=full cargo build --target aarch64-apple-ios -vv --verbose --release

mkdir ../../godot/lib/ios/ || true
cp target/aarch64-apple-ios/release/libdecentraland_godot_lib.dylib ../../godot/lib/ios/libdecentraland_godot_lib.dylib
Loading

0 comments on commit b99f0b6

Please sign in to comment.