Detect host system/build OS in project.xml

Is there any way to detect the host system on which the project is built on in the project.xml?

Not currently, it’s meant to be OS-dependent. What’s the use case? :slight_smile:

It would be possible using an HXP project file.

My specific use-case right now is to redefine the haxe-split executable as i want to define specific node options to insert when the executable is executed ( increase memory of the node process ).

But i need to switch between a node_modules/.bin/haxe-split for *nix and a node_modules/.bin/haxe-split.cmd for windows :sweat_smile:

Unix solution :

<haxeflag name="-D haxe_split=node --gc_interval=10000 --never_compact --max_old_space_size=8192 --max_semi_space_size=6144 --noconcurrent_sweeping node_modules/.bin/haxe-split" if="modular" />

Windows host system solution :

<haxeflag name="-D haxe_split=node --gc_interval=10000 --never_compact --max_old_space_size=8192 --max_semi_space_size=6144 --noconcurrent_sweeping node_modules/.bin/haxe-split.cmd" if="modular" />

I guess usually people add post build scripts in their IDE, like flash develop. But it should be possible to have this configured in the project config, instead of relying on outside tools.

Another use-case would be pre-build and post-build. And if necessary redefining executables of other libraries.

At first we were using

<postbuild command="cp">
	<arg>assets/Load_Screen/Load_Screen.bin build/html5/bin/lib/Load_Screen/Load_Screen.bin</arg>
</postbuild>

But that doesn’t work on Windows systems, as they don’t have cp. So now we have…

<postbuild command="sh">
	<arg>postbuild.sh</arg>
</postbuild>

With a postbuild.sh looking like this :

#!/bin/bash
set -e
if [[ "$OSTYPE" == "linux-gnu" || `uname` == 'Linux' || "$OSTYPE" == "freebsd"* || `uname` == 'FreeBSD' ]]; then
	cp assets/Load_Screen/Load_Screen.bin build/html5/bin/lib/Load_Screen/Load_Screen.bin
elif [[ "$OSTYPE" == "darwin"* || `uname` == 'Darwin' ]]; then
	cp assets/Load_Screen/Load_Screen.bin build/html5/bin/lib/Load_Screen/Load_Screen.bin
elif [[ "$OSTYPE" == "cygwin"* || `uname` == 'MINGW'* || `uname` == 'CYGWIN'* ]]; then
	cp assets/Load_Screen/Load_Screen.bin build/html5/bin/lib/Load_Screen/Load_Screen.bin
elif [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "win"* ]]; then
	copy assets/Load_Screen/Load_Screen.bin build/html5/bin/lib/Load_Screen/Load_Screen.bin
fi

As you can see this is a bit of an overkill when the sys package provides the OS_HOST information natively with Sys.systemName(). So it shouldn’t be hard to expose this as a definition e.g. HOST_WINDOWS, HOST_MAC, HOST_UNIX

I understand the sentiment that it would be nice to not have to rely on them, but cross-platform development unfortunately still needs to make these little differences. Right now i’m trying to handle it within the scripts themselves, which also is bad, as i have to rely on a windows user having a bash shell available. whereas it’d be easier to point a windows dev to a .bat and a unix dev to a .sh file.

Having this available in the build defs ( just not neko based ) would solve the deal : https://github.com/HaxeFoundation/neko/blob/093c49286582de796aab0b8a102bea9bcbe92be4/libs/std/sys.c#L184-L212