Skip to content

Commit f2f6a56

Browse files
authored
feat(ios): add tvOS support (#144)
1 parent 1fd6ef4 commit f2f6a56

41 files changed

Lines changed: 456 additions & 90 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CanvasNative.podspec‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
1313

1414
s.author = { "Osei Fortune" => "fortune.osei@yahoo.com" }
1515

16-
s.platforms = { :ios => "13.0", :visionos => "1.0" }
16+
s.platforms = { :ios => "13.0", :tvos => "13.0", :visionos => "1.0" }
1717

1818
s.source = { :git => "https://github.com/nativescript/canvas.git", :tag => "#{s.version}" }
1919

‎Makefile‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim
22
ARCHS_VISIONOS = aarch64-apple-visionos aarch64-apple-visionos-sim
3+
ARCHS_TVOS = aarch64-apple-tvos aarch64-apple-tvos-sim
34
ARCHS_ANDROID = i686-linux-android x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
45

56
XCFRAMEWORK = CanvasNative.xcframework
@@ -11,6 +12,8 @@ ios: $(XCFRAMEWORK)
1112

1213
visionos: $(ARCHS_VISIONOS)
1314

15+
tvos: $(ARCHS_TVOS)
16+
1417
android: GENERATE_ANDROID
1518

1619
ios-svg: GENERATE_IOS_SVG
@@ -39,6 +42,12 @@ $(ARCHS_VISIONOS): %:
3942
cargo +nightly build -Z build-std='std,panic_abort' \
4043
--target $@ --release -p canvas-ios
4144

45+
.PHONY: $(ARCHS_TVOS)
46+
$(ARCHS_TVOS): %:
47+
RUSTFLAGS="-Zlocation-detail=none -Zunstable-options -Cpanic=immediate-abort" \
48+
cargo +nightly build -Z build-std='std,panic_abort' \
49+
--target $@ --release -p canvas-ios
50+
4251
.PHONY: $(ARCHS_ANDROID)
4352
$(ARCHS_ANDROID): %:
4453
./tools/scripts/build-android.sh $@

‎Package.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import PackageDescription
1717

1818
let package = Package(
1919
name: "CanvasNative",
20-
platforms: [.iOS(.v12), .visionOS(.v1)],
20+
platforms: [.iOS(.v12), .tvOS(.v12), .visionOS(.v1)],
2121
products: [
2222
.library(name: "NativeScriptV8", targets: ["NativeScriptV8"]),
2323
],

‎crates/canvas-2d/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ raw-window-handle.workspace = true
2626
bitflags = "2.6.0"
2727
regex-lite = { workspace = true }
2828

29-
[target.'cfg(any(target_os = "ios", target_os="macos", target_os = "visionos"))'.dependencies]
29+
[target.'cfg(any(target_os = "ios", target_os="macos", target_os = "visionos", target_os = "tvos"))'.dependencies]
3030
foreign-types-shared = "0.3.1"
3131
objc2 = {workspace = true}
3232
objc2-foundation = { workspace = true }

‎crates/canvas-2d/src/context/drawing_images/mod.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Context {
191191
}
192192

193193
pub fn draw_image_dx_dy(&mut self, image: &Image, x: f32, y: f32) {
194-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))]
194+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
195195
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
196196
#[cfg(feature = "gl")]
197197
{
@@ -221,7 +221,7 @@ impl Context {
221221
}
222222

223223
fn draw_image(&mut self, image: &Image, src_rect: impl Into<Rect>, dst_rect: impl Into<Rect>) {
224-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))]
224+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
225225
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
226226
#[cfg(feature = "gl")]
227227
{
@@ -259,7 +259,7 @@ impl Context {
259259
}
260260

261261
fn draw_image_with_rect(&mut self, image: &Image, dst_rect: impl Into<Rect>) {
262-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))]
262+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
263263
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
264264
#[cfg(feature = "gl")]
265265
{

‎crates/canvas-2d/src/context/drawing_paths/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Context {
1212
path: Option<&mut Path>,
1313
fill_rule: Option<FillRule>,
1414
) {
15-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))]
15+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
1616
let _ = unsafe { objc2_foundation::NSAutoreleasePool::new() };
1717

1818
#[cfg(feature = "gl")]

‎crates/canvas-2d/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn bytes_to_data_n32_url(
101101
encoded_prefix.push_str(format);
102102
encoded_prefix.push_str(";base64,");
103103

104-
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "visionos"))]
104+
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "visionos", target_os = "tvos"))]
105105
let fmt = ColorType::BGRA8888;
106106

107107
#[cfg(any(target_os = "android"))]

‎crates/canvas-c/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ objc2-metal = { workspace = true }
4444

4545
# visionOS: display-link 0.2 is gated to ios/macos only, so RAF uses a CADisplayLink
4646
# shim (see src/raf/visionos.rs) built directly on objc2-quartz-core instead.
47-
[target.'cfg(target_os="visionos")'.dependencies]
47+
[target.'cfg(any(target_os="visionos", target_os="tvos"))'.dependencies]
4848
wgpu-core = { workspace = true, features = ["wgsl", "metal"] }
4949
wgpu-hal = { workspace = true, features = ["metal"] }
5050
objc2 = { workspace = true, features = ["std"] }

‎crates/canvas-c/src/c2d/context.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl CanvasRenderingContext2D {
290290
}
291291

292292
/* Raf */
293-
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos"))]
293+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
294294
#[no_mangle]
295295
pub extern "C" fn canvas_native_raf_create(
296296
callback: isize,
@@ -305,7 +305,7 @@ pub extern "C" fn canvas_native_raf_create(
305305
))))))
306306
}
307307

308-
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos"))]
308+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
309309
#[no_mangle]
310310
pub extern "C" fn canvas_native_raf_release(value: *mut crate::Raf) {
311311
if value.is_null() {
@@ -319,7 +319,7 @@ pub extern "C" fn canvas_native_raf_release(value: *mut crate::Raf) {
319319
}
320320
}
321321

322-
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos"))]
322+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
323323
#[no_mangle]
324324
pub extern "C" fn canvas_native_raf_start(raf: *mut crate::Raf) {
325325
if raf.is_null() {
@@ -329,7 +329,7 @@ pub extern "C" fn canvas_native_raf_start(raf: *mut crate::Raf) {
329329
raf.0.start();
330330
}
331331

332-
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos"))]
332+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
333333
#[no_mangle]
334334
pub extern "C" fn canvas_native_raf_stop(raf: *mut crate::Raf) {
335335
if raf.is_null() {
@@ -339,7 +339,7 @@ pub extern "C" fn canvas_native_raf_stop(raf: *mut crate::Raf) {
339339
raf.0.stop()
340340
}
341341

342-
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos"))]
342+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
343343
#[no_mangle]
344344
pub extern "C" fn canvas_native_raf_get_started(raf: *const crate::Raf) -> bool {
345345
if raf.is_null() {
@@ -349,7 +349,7 @@ pub extern "C" fn canvas_native_raf_get_started(raf: *const crate::Raf) -> bool
349349
raf.0.started()
350350
}
351351

352-
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos"))]
352+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
353353
#[no_mangle]
354354
pub extern "C" fn canvas_native_raf_stop_and_clear(raf: *mut crate::Raf, timeout_ms: u64) {
355355
if raf.is_null() {
@@ -361,7 +361,7 @@ pub extern "C" fn canvas_native_raf_stop_and_clear(raf: *mut crate::Raf, timeout
361361
raf.0.clear_callback();
362362
}
363363

364-
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos"))]
364+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
365365
#[no_mangle]
366366
pub extern "C" fn canvas_native_raf_clear_callback(raf: *mut crate::Raf) {
367367
if raf.is_null() {

‎crates/canvas-c/src/lib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod helper;
2828
pub use helper::*;
2929
mod image_asset;
3030
pub use image_asset::*;
31-
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos"))]
31+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
3232
mod raf;
3333
mod text_decoder;
3434
pub use text_decoder::*;
@@ -38,7 +38,7 @@ mod webgl;
3838
pub use webgl::*;
3939
pub mod impl_test;
4040
/* Raf */
41-
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos"))]
41+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "visionos", target_os = "tvos"))]
4242
#[derive(Clone)]
4343
pub struct Raf(raf::Raf);
4444
/* Raf */

0 commit comments

Comments
 (0)