Question: tvOS support

After further analysis I got that I’m stuck in the UPDATE phase which is before the BUILD phase, that’s why I cannot see the cpp stuff going on.

So given that it’s fine, I need to find a solution to the following error:

Error: Source path "/usr/lib/haxe/lib/hxcpp/3,2,102/lib/tvOS/libstd.tvos.a" does not exist

Since I defined my new target to have the “tvos” suffix, it expects that hxcpp has the same target available for the other libraries.
Do I have to patch hxcpp as well or is there any way I can tell hxcpp to make me the libraries I need with the name I want directly from lime?

If the binaries are incompatible, then perhaps we need “tvos” instead of “ios”. Otherwise, we might be able to hack use of (say) iOS binaries from HXCPP and tvOS binaries from Lime.

The kosher HXCPP solution is to add support in the build tool, and add a new toolchain XML. However, without modifying HXCPP it’s possible to tell it what toolchain and platform prefix to use, for example:

Defining “toolchain” will make HXCPP look for “$value-toolchain.xml” in the classpath. Setting “BINDIR” will tell it what directory to use (such as “tvOS”)

If you have a working “rebuild” command for the tools, you could lime rebuild hxcpp tvos to compile it :slight_smile:

Using iOS libraries for Apple TV targets is discouraged and it will probably become an error in XCode 7.1 or the following release. So I’m going directly down the kosher way :smile:

I’ve got some work to do but I feel I’m getting there. The hardest thing was rebuilding the build.n tool as I didn’t know where the source code was, but in the end I managed to do that, too.

Right now I’m back at home and working on a different box and for some reason lime is throwing the following error at me:

 - Running command: g++ -o ndll/Mac64/lime.ndll -stdlib=libstdc++ -fpic -fPIC -dynamiclib -m64 -framework Cocoa -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -fvisibility=hidden -l iconv -framework IOKit -framework Foundation -framework CoreAudio -framework CoreVideo -framework Cocoa -framework OpenGL -framework AudioToolbox -framework AudioUnit -framework ForceFeedback -framework Carbon -framework AppKit -framework OpenAL @/Users/tanis/Documents/lime/project/obj/darwin64//all_objs
ld: can't open output file for writing: ndll/Mac64/lime.ndll, errno=2 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

I don’t know what’s happening as the permissions on the folders are fine. That’s weird.

Is an application running that’s using it?

Nope. I switched back to the non-dev version of hxcpp and it worked, so I guess it’s either that the master branch of hxcpp has a bug or I introduced one (more likely).

Having a deeper look at my code, it complains with this stuff (it didn’t happen on the other box, though… weird)

MacBook-Pro-di-Valerio:hxcpp tanis$ haxe compile.hxml
FileGroup.hx:46: characters 28-43 : Class<haxe.io.Path> has no field isAbsolute
BuildTool.hx:809: characters 25-40 : Class<haxe.io.Path> has no field isAbsolute 

I suppose it’s due to a different version of haxe… gonna try updating.

Yep! That was it… I was still on version 3.1.3
I upgraded to 3.2.0 and now that’s fine.

Now I need to find out what’s wrong with my newly created tvos target in hxcpp as the result is only the following (no libraries being compiled for the time being):

MacBook-Pro-di-Valerio:project tanis$ neko build.n tvos
neko run.n Build.xml -Dappletvos -DHXCPP_ARM64 -DHXCPP_M64 -DHXCPP_CPP11 /Users/tanis/Documents/hxcpp/project/
neko run.n Build.xml -Dappletvsim -DHXCPP_M64 -DHXCPP_CPP11 /Users/tanis/Documents/hxcpp/project/
neko run.n Build.xml -Dappletvsim -DHXCPP_CPP11 /Users/tanis/Documents/hxcpp/project/

I would still recommend trying lime rebuild hxcpp tvos, at least, that’s what I use for HXCPP rebuilds

It was mainly because my changes weren’t yet correct. I managed to get the compile phase started but now I’ve hit a problem with std libraries as I’d need to patch those as well.

Have a look at the output:

MacBook-Pro-di-Valerio:project tanis$ neko build.n tvos -DDEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer/
neko run.n Build.xml -Dappletvos -DHXCPP_ARM64 -DHXCPP_M64 -DHXCPP_CPP11 -DDEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer/ /Users/tanis/Documents/hxcpp/project/
xcrun --sdk appletvos9.0 clang++ -c -stdlib=libc++ -O2 -arch arm64 -isysroot /Applications/Xcode-beta.app/Contents/Developer//Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.0.sdk -mappletvos-version-min=9.0 -Wno-parentheses -Wno-null-dereference -Wno-unused-value -Wno-bool-conversion -fno-stack-protector -DAPPLETV=APPLETV -DAPPLETVOS=APPLETVOS -DSTATIC_LINK -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=0 -I/Users/tanis/Documents/hxcpp/include -fexceptions -fstrict-aliasing -x c++ -Wno-invalid-offsetof /Users/tanis/Documents/hxcpp/project/libs/std/Sys.cpp -o/Users/tanis/Documents/hxcpp/project/libs/std/obj/appletvos-c11-64/91271e68_Sys.o
xcrun --sdk appletvos9.0 clang++ -c -stdlib=libc++ -O2 -arch arm64 -isysroot /Applications/Xcode-beta.app/Contents/Developer//Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.0.sdk -mappletvos-version-min=9.0 -Wno-parentheses -Wno-null-dereference -Wno-unused-value -Wno-bool-conversion -fno-stack-protector -DAPPLETV=APPLETV -DAPPLETVOS=APPLETVOS -DSTATIC_LINK -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=0 -I/Users/tanis/Documents/hxcpp/include -fexceptions -fstrict-aliasing -x c++ -Wno-invalid-offsetof /Users/tanis/Documents/hxcpp/project/libs/std/Xml.cpp -o/Users/tanis/Documents/hxcpp/project/libs/std/obj/appletvos-c11-64/91271e68_Xml.o
Error: 2015-09-29 23:18:32.529 xcodebuild[83558:1454269] [MT] PluginLoading: Required plug-in compatibility UUID CC0D0F4F-05B3-431A-8F33-F84AFCB2C651 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Unity4XC.xcplugin' not present in DVTPlugInCompatibilityUUIDs
/Users/tanis/Documents/hxcpp/project/libs/std/Sys.cpp:278:16: error: call to unavailable function 'system': not available on tvOS
        int result =  system(val_string(cmd));
                      ^~~~~~
/Applications/Xcode-beta.app/Contents/Developer//Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.0.sdk/usr/include/stdlib.h:177:6: note: candidate function has been explicitly made unavailable
int      system(const char *) __DARWIN_ALIAS_C(system) __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_0,__MAC_NA,__IPHONE_2_0,__IPHONE_8_0, "Use posix_spawn APIs instead.") __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
         ^
/Users/tanis/Documents/hxcpp/project/libs/std/Sys.cpp:699:10: fatal error: 'crt_externs.h' file not found
#include <crt_externs.h>
         ^
2 errors generated.
2015-09-29 23:18:32.515 xcodebuild[83559:1454270] [MT] PluginLoading: Required plug-in compatibility UUID CC0D0F4F-05B3-431A-8F33-F84AFCB2C651 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Unity4XC.xcplugin' not present in DVTPlugInCompatibilityUUIDs
#### Error building neko -Dappletvos -DHXCPP_ARM64 -DHXCPP_M64 -DHXCPP_CPP11 -DDEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer/

The first error is easy to fix in Sys.cpp

But I’m having troubles with Process.cpp as I do not know how to work around this one:

Error: /Users/tanis/Documents/hxcpp/project/libs/std/Process.cpp:154:13: error: call to unavailable function 'fork': not available on tvOS
   p->pid = fork();
            ^~~~
/Applications/Xcode-beta.app/Contents/Developer//Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.0.sdk/usr/include/unistd.h:446:8: note: candidate function has been explicitly made unavailable
pid_t    fork(void) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
         ^
/Users/tanis/Documents/hxcpp/project/libs/std/Process.cpp:166:7: error: call to unavailable function 'execvp': not available on tvOS
      execvp(val_string(cmd),argv);
      ^~~~~~
/Applications/Xcode-beta.app/Contents/Developer//Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.0.sdk/usr/include/unistd.h:445:6: note: candidate function has been explicitly made unavailable
int      execvp(const char *, char * const *) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
         ^
2 errors generated.

It’s getting late here… (midnight) and I’ve got to get up at 5 in the morning, so I’m leaving it there for the time being. If you want to have a look at the code, I pushed everything there: https://github.com/tanis2000/hxcpp/commits/tvos

Bear in mind that you need XCode 7.1 beta 2 to be able to compile against the AppleTVOS platform.
Cheers!

It looks like I managed to fix the stuff in hxcpp and build some libraries for tvOS. I’ve still got to check if they actually work. I’m on lime now. Time to see if SDL is giving troubles or what.

I’m stuck with lime now. There’s a problem with my newly created tvos target where it cannot find the OpenGL headers.
I run: lime rebuild tvos -v -clean
Which in turn runs the following command:
haxelib run hxcpp Build.xml -Dtvos -DHXCPP_CPP11 -DHXCPP_ARM64 -Dlime-openal -Dtools=2.6.6 -Drebuild=1 -Dlime-cairo -Dno-compilation -Dlime-opengl -Dlime-native -Dlime-curl -verbose

And it looks ok to me.

But while compiling I get the following error:

 - Compiling src/graphics/opengl/OpenGLBindings.cpp : g++ -Iinclude -Ilib/cairo/include -Ilib/cairo/include/configs/default/ -DLIME_CAIRO -DHAVE_CONFIG_H -DCAIRO_HAS_FT_FONT -Ilib/curl/include/ -DLIME_CURL -DCURL_STATICLIB -Ilib/jpeg/ -DLIME_JPEG -Ilib/freetype/include -DLIME_FREETYPE -Ilib/harfbuzz/src -DLIME_HARFBUZZ -Ilib/lzma/src -DLIME_LZMA -Ilib/ogg/include/ -Ilib/vorbis/include/ -DLIME_OGG -Ilib/openal/include/ -DLIME_OPENAL -DAL_LIBTYPE_STATIC=1 -DLIME_OPENGL -Ilib/png/ -Ilib/zlib/ -DLIME_PNG -Ilib/sdl/include/ -Ilib/sdl/include/configs/default/ -DHAVE_LIBC -DLIME_SDL -D__IPHONEOS__ -D__APPLETVOS__ -DAPPLETV -c -fvisibility=hidden -stdlib=libstdc++ -O2 -I/Users/tanis/Documents/hxcpp/include -DHX_MACOS -m64 -Wno-parentheses -Wno-unused-value -Wno-format-extra-args -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=0 -x c++ -frtti -Wno-invalid-offsetof ./src/graphics/opengl/OpenGLBindings.cpp -o/Users/tanis/Documents/lime/project/obj/darwin64/e345332b_OpenGLBindings.o
Error in building thread
g++ -Iinclude -Ilib/cairo/include -Ilib/cairo/include/configs/default/ -DLIME_CAIRO -DHAVE_CONFIG_H -DCAIRO_HAS_FT_FONT -Ilib/curl/include/ -DLIME_CURL -DCURL_STATICLIB -Ilib/jpeg/ -DLIME_JPEG -Ilib/freetype/include -DLIME_FREETYPE -Ilib/harfbuzz/src -DLIME_HARFBUZZ -Ilib/lzma/src -DLIME_LZMA -Ilib/ogg/include/ -Ilib/vorbis/include/ -DLIME_OGG -Ilib/openal/include/ -DLIME_OPENAL -DAL_LIBTYPE_STATIC=1 -DLIME_OPENGL -Ilib/png/ -Ilib/zlib/ -DLIME_PNG -Ilib/sdl/include/ -Ilib/sdl/include/configs/default/ -DHAVE_LIBC -DLIME_SDL -D__IPHONEOS__ -D__APPLETVOS__ -DAPPLETV -c -fvisibility=hidden -stdlib=libstdc++ -O2 -I/Users/tanis/Documents/hxcpp/include -DHX_MACOS -m64 -Wno-parentheses -Wno-unused-value -Wno-format-extra-args -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=0 -x c++ -frtti -Wno-invalid-offsetof ./src/graphics/opengl/OpenGLBindings.cpp -o/Users/tanis/Documents/lime/project/obj/darwin64/e345332b_OpenGLBindings.o
Error: In file included from ./src/graphics/opengl/OpenGLBindings.cpp:4:
./src/graphics/opengl/OpenGL.h:20:10: fatal error: 'OpenGLES/ES1/gl.h' file not found
#include <OpenGLES/ES1/gl.h>
         ^
1 error generated.

What part of lime is in charge of telling the compiler where the platform SDK is located?

Maybe you need to add || tvOS here https://github.com/openfl/lime/blob/master/project/Build.xml#L308 or a similar section.
Though there’s no ios section so I’m not sure.

Yes, you’re probably right. And I suppose there’s no iOS section as the iOS still uses the legacy lime.

I tried adding a section in there with the following content:

		<section if="tvos">

			<vflag name="-framework" value="UIKit" />
			<vflag name="-framework" value="Foundation" />
			<vflag name="-framework" value="CoreAudio" />
			<vflag name="-framework" value="CoreVideo" />
			<vflag name="-framework" value="OpenGLES" />
			<vflag name="-framework" value="AudioToolbox" />
			<vflag name="-framework" value="AudioUnit" />
			<vflag name="-framework" value="OpenAL"/>

			<lib name="-ldl" />
			<lib name="-lEGL" />
			<lib name="-lGLESv2" />

		</section>

I also tried adding to the LIME_OPENGL section the following:

		<compilerflag value="-I${DEVELOPER_DIR}/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS${TVOS_VER}.sdk/" if="tvos" />

		<file name="src/graphics/opengl/OpenGLBindings.cpp" />

but I still get the same error that it can’t find the OpenGLES stuff… I have no clue why the iOS build works and mine doesn’t… :frowning:

Why is it that running haxelib run hxcpp Build.xml -Dtvos -DHXCPP_CPP11 -DHXCPP_ARM64 -Dlime-openal -Dtools=2.6.6 -Drebuild=1 -Dlime-cairo -Dno-compilation -Dlime-opengl -Dlime-native -Dlime-curl -verbose

gives the following message:

 __
/\ \
\ \ \___    __  _   ___   _____   _____
 \ \  _ `\ /\ \/'\ /'___\/\ '__`\/\ '__`\
  \ \ \ \ \\/>  <//\ \__/\ \ \L\ \ \ \L\ \
   \ \_\ \_\/\_/\_\ \____\\ \ ,__/\ \ ,__/
    \/_/\/_/\//\/_/\/____/ \ \ \/  \ \ \/
                            \ \_\   \ \_\
                             \/_/    \/_/

hxcpp (Haxe C++ Runtime Support) (3.2.0)

Using makefile: Build.xml
Reading HXCPP config: /Users/tanis/.hxcpp_config.xml
No specified toolchain

I don’t get why it’s not selecting a toolchain. It should go for the toolchains defined as dependent from tvos in hxcpp. And they’re appletvos and appletvsim as defined in my BuildTool.hx

  if (defines.exists("tvos"))
  {
     if (defines.exists("simulator"))
        defines.set("appletvsim", "appletvsim");
     else if (!defines.exists ("appletvsim"))
        defines.set("appletvosos", "appletvos");
     defines.set("appletv", "appletv");
  }

Do you set the “toolchain” value within the HXCPP tools when “tvos” is defined?

Yep, I got it working in the end! HXCPP and Lime are working fine. I managed to make it create a tvOS project and the libraries being compiled and copied over seem to be the correct ones.

But I’ve still got trouble when compiling “Build Haxe” target. It compiles but it’s creating a file called ApplicationMain-debug in the correct build folder instead of libApplicationMain-debug.appletvos-64.a.

If I manually rename the file, then it looks like it’s not actually been built for the correct arm64 architecture as I get the following error:

ld: warning: ignoring file /Users/tanis/Documents/openfl-test-tvos/Export/tvos/DisplayingABitmap/lib/arm64-debug/libApplicationMain.a, file was built for x86_64 which is not the architecture being linked (arm64): /Users/tanis/Documents/openfl-test-tvos/Export/tvos/DisplayingABitmap/lib/arm64-debug/libApplicationMain.a
ld: entry point (_main) undefined. for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

But the Options.txt file shows that the 64 bit architecture has been defined:

HXCPP_ARM64=1
haxe3=1
haxe_ver=3.2
hxcpp_api_level=321
lime=2.6.6
lime-cairo=1
lime-curl=1
lime-native=1
lime-openal=1
lime-opengl=1
lime_cairo=1
lime_curl=1
lime_native=1
lime_openal=1
lime_opengl=1
mobile=1
native=1
no-compilation=1
no_compilation=1
openfl=3.3.6
openfl-native=1
openfl-next=1
openfl_native=1
openfl_next=1
tools=2.6.6
tvos=1
hxcpp=/Users/tanis/Documents/hxcpp/

After much grief and sweat I managed to get my test project to compile and run on the Apple TV. On the other hand, the DisplayingABitmap sample only shows a black screen. Now I need to find out why that’s happening.

Is there any way to debug this?

I had to modify hxcpp, lime and most of the included dependencies. The problem with the dependencies is that I changed them all directly in the cloned repo, so I cannot commit them anywhere as they all point to the HaxeFoundation repos.

I think I need some help from you @singmajesty if we want to pull in my changes.
Cheers!

If you have changed files, diffs, or anything else, I could look at trying to merge the change.

Try using something simple, like drawing shapes, and see if that works. If it does, but you cannot load a bitmap, perhaps the Assets load is failing, and may have something to do with the current working directory when running the application. Take a look at the templates/haxe/DefaultAssetLibrary.hx class in Lime, and try and debug the manifest loading. Might need to patch in a hack in there to get it to work :slight_smile:

Tomorrow in the morning I’ll send you the files I patched.

I also tried replacing the SDL version with the one in slime73’s repository but it didn’t work (and my changes were pretty much the same, just based on your version od SDL instead).

I’ll try with some shapes and let you know. Is there any way to get the output of the SDL errors/warnings in the console of Xcode?
Or any other way to dump something to the console from? I fear it might have to do with the OpenGL device.

As a different try I also grabbed the latest SDL version from their master repo and adapted the iOS demo for the Apple TV but even though it run, it was showing a grey screen (the standard background in tvOS apparently).

I noticed that in their demos the render() function was not being called which lead me to thinking there’s a problem with the canvas or something like that. But then again I don’t know anything about SDL’s internals.

If it helps, you can also try Lime “HelloWorld”, “SimpleImage” or “HerokuShaders” and see if any of those work

Gonna try those as well. And I’m going to cross my fingers, too. :smile: