Ensure that a Haxe program will run on all platforms - haxe

I plan to write Haxe libraries in a subset of Haxe that will compile to every Haxe target language. Is there any way to verify that a Haxe program will compile to all target languages, and is it possible to do this without manually testing the compiled code on each target platform?
For example, is there a way to ensure that the following code is valid on every target platform, without testing it manually on every single platform?
class Test {
static function main(){
trace("How can I check to see which platforms this program will run on?");
}
}
EDIT: I have written a compile.hxml file that compiles the class Test.hx to various target languages. All the necessary haxelib libraries will need to be installed first in order for it to work properly.
-js test.js
-main Test
--next
-php www
-main Test
--next
-cpp cpp
-debug
-main Test
--next
-main Test
-java java
--next
-cs test
-main Test
-D haxe3

I have done some similar things with a few of my libraries (mdown and detox), and I was able to test several of the platforms using MUnit / MassiveUnit:
https://github.com/massiveinteractive/MassiveUnit
This is a unit testing platform that you can use to check your behaviour across multiple targets. There is also utest, and possibly others.
Currently munit can automatically run tests for your code on the following targets:
Neko
Flash 8
Flash 9+
Javascript
CPP
There are instructions for adding support for other targets here
(If you don't know much about unit testing - it's a way to write lots of small tests to make sure your library/code behaves as expected, and is perfect for checking that things function across platforms, as well as making sure you don't break things when you change your code.)

Related

Haxe compiling to C++ and JS source

I am trying to write source code in one language and have it converted to both native c++ and JS source. Ideally the converted source should be human readable and resemble the original source as best it can. I was hoping haxe could solve this problem for me. So I code in haxescript and have it convert it to its corresponding C++ and JS source. However the examples I'm finding of haxe seems to create the final application for you. So with C++ it will use msbuild (or whatever compiler it finds) and creates the final exe for you from generated C++ code. Does haxe also create the c++ and JS source code for you to view or is it all done internally to haxe and not accessible? If it is accessible then is it possible to remove the building side of haxe so it simply creates the source code and stops?
Thanks
When you generate CPP all the intermediate files are generated and kept wherever you decide to generate your output (the path given using -cpp pathToOutput). The fact that you get an executable is probably because you are using the -main switch. That implies an entry point to your application but that is not really required and you can just pass to the command line a bunch of types that you want to have built in your output.
For JS it is very similar, a single JS file is generated and it only has an entry point if you used -main.
Regarding the other topic, does your Haxe code resembles the generated code the answer is yes, but ... some of the types (like Enum and Abstract) only exist in Haxe so they will generate code that functionally works but it might look quite different. Also Haxe has an always-on optimizer/analyzer that might mungle your code in unexpected ways (the analyzer can be disabled). I still find that it is not that difficult to figure out the Haxe source from the generated code. JS has support for source mapping which is really useful for debugging. So in the end, Haxe doesn't do anything to obfuscate your generated code but also doesn't do much to try to preserve it too strictly.

How do I cross-compile a QT application for imx6?

How do I cross-compile a QT application for a Freescale Hummingboard(imx6(arm))?
There are some guides around, but I've not been able to complete one with success.
The following (and more) guides give me a compile error on ./configure
http://forum.solid-run.com/linux-on-cubox-i-and-hummingboard-f8/qt5-3-on-hummingboard-t2072.html
https://community.freescale.com/docs/DOC-94066
When I run the ./configure command (With recommended commands, I've tried this with a lot of possibilities for commands but got none working). I got a compile error for all the external libraries QT uses (zlib, libjpeg, libpng, etc.). So it's a dead end from there.
I've tried a lot more stuff, I don't even remember all the stuff I've tried, but I got nothing working.
I'm trying to use mini-distribution for the Hummingboard. It's a system without window manager that is able to run QT applications (QT5). The build tool I'm trying to use is gcc-linaro-arm-linux-gnueabi, I'm using QT Creator. I've got QT working on the Hummingboard, I just can't compile anything for it.
I managed building an application for the IMX6 finally. Here is how I did it for other's. It's not an optimal solution but it is an solution.
I use Buildgear to build mini-distirbution as OS (Google it, not enough links with my reputation). I append my own application to this mini-distribution to also build it. This is done by placing creating a folder in the buildfiles/cross/cross-hummingboard folder and adding a buildfile (mine look like this http://pastebin.com/bZkJUiry). In this folder I also place a .tar of the project files (including the .pro). To get it to build I add "qt-gui" as a dependency to the fs (buildfiles/cross/cross-hummingboard/fs) by adding it to the list of depends.
I then run buildgear build fs, which will create an (Tarred) image including my (working) qt-application! I then extract the ./qt-gui executable and ssh it to the Hummingboard.
Of course this is all a bit cumbersome so I made a script that automates this all: http://pastebin.com/jFM6rZyY
It copies and Tars sources, compiles it together with the fs, extracts the executable, ssh's the file to the hummingboard and runs it. Takes about 3 minutes building but it works which is what counts for me at this point.

Retrieve Standard User Information in Haxe

I have finally had some time to start playing with Haxe, i find it a great concept but i am having trouble trying to deduce how i would go about getting the current system user's name or "special folder" locations.
In my case, the User's home folder, documents folder or update folder. My target language is Java, and perhaps later C#... But i have found no real way to query the system for this information directly. All i have found so far is how to query environment variables... Which have a ton of variability.
The Haxe std lib does not provide such specific function. However, it doesn't prevent us to use target-specific APIs.
#if java
import java.lang.System;
#elseif cs
import cs.system.Environment;
import cs.system.Environment.Environment_SpecialFolder;
#end
class Test {
static function main() {
#if java
//http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#getProperties%28%29
trace(System.getProperty("user.home")); //Test.hx:11: C:\Users\Andy
#elseif cs
//https://msdn.microsoft.com/en-us/library/system.environment.specialfolder
trace(Environment.GetFolderPath(Environment_SpecialFolder.UserProfile)); //Test.hx:14: C:\Users\Andy
#end
}
}
build.hxml:
-main Test
-java bin
-cmd java -jar bin/Test.jar
--next
-main Test
-cs bin
# Environment_SpecialFolder.UserProfile is available since .net 4.0
-D net-ver=40
-cmd bin\bin\Test.exe

Turning off unittest execution of third-party code

I'm trying to understand how the '-unittest' dmd switch can be used to select which files have their unittests executed.
I have a file, "a.d", containing a unittest block. File "a.d" imports from a third-party module (requiring the file "b1.d" and in turn "b2.d") which contain their own unittest blocks.
I don't want to run the tests in the third-party code: I just want to run the tests in a.d.
If I compile the third-party code first
dmd -c b1.d b2.d
then try to link it with my code with the unittests copied in
dmd -unittest a.d b1.o b2.o
then I get an error saying that the module in b1.d which a.d is trying to import is in a file that cannot be read.
Can anyone show me how to accomplish this?
Thanks!
What you want to do is not possible because a.d has imported b1.d and b2.d. It means that those modules must be passed to the compiler.
If you want to link some *.o files it's more complex: you have to write an interface (*.di file for them just like for a *.so) thus it's not a good idea to use this mechanism to bypass the unittests. (although this could work it's a bit heavy).
A more straightforward way to arbitrary select some unittests is to use the trait getUnitTests. It's really more the way to go.
You are almost there. Just use separate compilation and linking steps, i.e.
dmd -c -unittest a.d
and then:
dmd a.o b1.o b2.o
That's it.

Can I build static library that main component is header file(.h) with NDK?

I want to convert my cpp code for static library into Android library.
For this, I'm attempting to use NDK.
But I read NDK documentation and it said that only source code is able to be input for building, "Android.mk".
My Questtion is "Is there any way to build static library for Android system with my cpp library?"
Top module of my cpp library is header file and it can be built on Windows system as ".lib".
Thank you!
Your cpp library should be built with NDK toolchain as "libyourname.a" to begin with. You don't need Android.mk for that, even though in many cases deriving a standards-compliant Android.mk is trivial, and makes the developer's life happier in the long run (See, e.g., github).
The next step should be to prepare a JNI wrapper dynamic library (shared object, .so), which can be loaded from your Java app. That "libyourname_jni.so" will probably have its own, separate Android.mk file. Well, Java is not a must: you can use NativeActivity, or maybe some alternative frameworks.
I suggest the following reading to understand the whole process: http://thesoftwarerogue.blogspot.co.il/2010/05/porting-of-libcurl-to-android-os-using.html

Resources