haxefoundation / hxcs Goto Github PK
View Code? Open in Web Editor NEWHaxe C# support library. Build scripts and support code.
License: The Unlicense
Haxe C# support library. Build scripts and support code.
License: The Unlicense
We have business logic on Haxe.
Now we try to start new platform - Universal Windows platform.
But generated C# contains errors
1>uwp\src\Date.cs(48,55,48,78): error CS0234: The type or namespace name 'TimeZone' does not exist in the namespace 'System' (are you missing an assembly reference?)
1>uwp\src\haxe\rtti\Meta.cs(33,40,33,51): error CS1061: 'Type' does not contain a definition for 'IsInterface' and no extension method 'IsInterface' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)
1>uwp\src\haxe\io\BytesBuffer.cs(26,24,26,33): error CS1061: 'MemoryStream' does not contain a definition for 'GetBuffer' and no extension method 'GetBuffer' accepting a first argument of type 'MemoryStream' could be found (are you missing a using directive or an assembly reference?)
1>uwp\src\haxe\CallStack.cs(81,16,81,26): error CS1061: 'StackTrace' does not contain a definition for 'FrameCount' and no extension method 'FrameCount' accepting a first argument of type 'StackTrace' could be found (are you missing a using directive or an assembly reference?)
1>uwp\src\cs\internal\Runtime.cs(385,170,385,222): error CS0039: Cannot convert type 'System.Type' to 'System.Reflection.MemberInfo' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
1>uwp\src\cs\internal\Runtime.cs(523,51,523,60): error CS1061: 'Type' does not contain a definition for 'GetMember' and no extension method 'GetMember' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)
1>uwp\src\cs\internal\Runtime.cs(532,13,532,24): error CS1061: 'Type' does not contain a definition for 'IsCOMObject' and no extension method 'IsCOMObject' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)
1>uwp\src\cs\internal\Runtime.cs(641,133,641,144): error CS0117: 'BindingFlags' does not contain a definition for 'SetProperty'
etc
Why are assemblies currently not compiled with msbuild/xbuild?
I've also found that assemblies compiled with csc is different from the one generated with msbuild for some reason. It looks like it's working in the same way, but slower than msbuild version for some reason. I verified that cmd file has /optimize option.
This also leads to different behaviour in other cases. For example, with references containing / in its path instead of \ (backslash). This compiles successfully with csc, but not with msbuild.
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-5.0
I am currently trying to use the http client. Unfortunately it is not available in the haxe context.
Also as alternative: cs.system.net.WebRequest
WebHeaderCollection is not avaible on net 50 only on 45
Having for example the following piece of code:
interface ITest<K, V>
{
function keys():Array<K>;
function values():Array<V>;
}
interface ISubTest extends ITest<String, String>
{
}
Generates the following C# code for ISubTest:
public interface ISubTest : global::haxe.lang.IHxObject, global::ITest<object, object> {
}
As you can see it completely loses the types we want to use. I tried different types, and I was always getting object for the generic type. Furthermore, this one:
interface ITest<K, V>
{
function keys():Array<K>;
function values():Array<V>;
}
interface ISubTest extends ITest<String, Dynamic>
{
}
class TestClass implements ISubTest
{
public function keys():Array<String>
{
return null;
}
public function values():Array<Dynamic>
{
return null;
}
}
Doesn't compile at all, because it generates some invalid implementation of the interface in TestClass
:
global::Array global::ITest<object, object>.keys() {
return ((global::Array) (this.keys()) );
}
public virtual global::Array<object> keys() {
return null;
}
public virtual global::Array values() {
return null;
}
I would say this is a rather important issue.
Hi,
I tried to extend UserControl but it's give a strange error.
I succeed to solve this problem by add @:nativeGen to class definition but it's should work like that?
Here gist : https://gist.github.com/mikicho/44d57f31f017fa5d86f8
Thanks,
Miki
When trying to compile a .net 4.5 project (depending on Azure web jobs SDK)
adding
-net-lib C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\mscorlib.dll
results in the following error:
PeReader.Error_message("Error reading compressed data. Invalid first byte: e5")
Build halted with errors (haxe.exe).
Also see
HaxeFoundation/haxe#4151 (comment)
C# code generated by hxcs has no comments from the haxe source.
It would be very useful to have this at least as an option (not default behavior).
The Haxe API documentation at http://api.haxe.org/EReg.html#matched states:
If no such sub-group exists, an exception is thrown
On C# targets however no exception is thrown, but null is returned.
Example:
class Test {
static function main() {
var pattern = ~/test/g;
pattern.match("test");
trace(pattern.matched(1)); // prints "null" on C#, but should throw an exception
}
}
The below code traces
Main.hx:17: haxe.lang.Null 1[System.Object]
Main.hx:23: haxe.lang.Null 1[System.Object]
I would expect it to trace
ASD
ASD
package;
import cs.Lib;
import haxe.ds.StringMap;
class Main
{
static function main()
{
var sm = new StringM();
sm.set("ASD", "ASD");
trace(sm.get("ASD"));
checkme(sm);
}
static function checkme(s){
trace(cast(s, StringM).get("ASD"));
}
}
class StringM extends StringMap<Any>
{
public var tN:String;
public var isTypedObject(get, null):Bool;
public function new(?t:String) {
super();
if (null != t) {
this.tN = t;
}
}
private function get_isTypedObject():Bool {
return (null != this.tN && "" != this.tN);
}
public static function fromMap(map:StringMap<Any>):StringM {
return cast (Reflect.copy(map), StringM);
}
public override function toString():String {
return "StringM " + super.toString();
}
}
Hi,
how can I add -pkg:packageName to the build command ?
I looked into hxcs / build-tool / src / compiler / cs / CSharpCompiler.hx but it doesn't seems possible.
Thanks for your time.
On windows, it seems that the installed VisualStudio compilers "override" the mono ones as default. It would be cool to be able to set the default compiler to Mono also on windows..!
hxcs v3.2.0
haxe v3.4.0
static var b:Array<Int> = a.concat([1]);
static var a:Array<Int> = [1];
this code will compile successfuly, and work fine targeting js or as3, but not c#.
this initialization of 'a' and 'b' arrays will be moved into constructor, and left in presentet sequence:
first, b = a.concat(), then, a = [].
static var a:Array<Int> = [1];
static var b:Array<Int> = a.concat([1]);
in this case it will work.
This issue will trigger no wornings of errors, exept 'null referense exception' during C# runtime.
On mac using many dll like the ones associated with GTK require the related dylib's used to be associated properly. Currently there is no documentation on how this should be done or if this is currently possible. It seems to be a general issue causing problems for mono developers working on mac, and more of a problem for haxe developers because the workflow is not standards so googling will not provide a solution that is easy to understand in a haxe context. eg:
http://stackoverflow.com/questions/13885454/mono-on-osx-couldnt-find-gtksharpglue-2-dll
with the haxe workflow as I said it's not so obvious what the best approach is, but the basic concept is that mono does not find or understand dylib's without a config.dll file next to the dll file.
http://www.mono-project.com/docs/advanced/pinvoke/dllmap/
For instance if we try to use c# on a mac to do gtk we would need an hxml files like the linux one found in this project:
https://github.com/cambiata/haxe-cs-gtk-cairo/blob/master/build-linux.hxml
so the hxml for a mac might look like
-cs bin-mac
-cp src
-main Main
-D net-ver=40
-D verbose
-net-lib Library/Frameworks/Mono.framework/Libraries/gac/atk-sharp/2.12.0.0__35e10195dab3c99f/atk-sharp.dll
-net-lib Library/Frameworks/Mono.framework/Libraries/gac/pango-sharp/2.12.0.0__35e10195dab3c99f/pango-sharp.dll
-net-lib/Library/Frameworks/Mono.framework/Libraries/gac/gdk-sharp/2.12.0.0__35e10195dab3c99f/gdk-sharp.dll
-net-lib Library/Frameworks/Mono.framework/Libraries/gac/gtk-sharp/2.12.0.0__35e10195dab3c99f/gtk-sharp.dll
-net-lib Library/Frameworks/Mono.framework/Libraries/gac/glib-sharp/2.12.0.0__35e10195dab3c99f/glib-sharp.dll
-net-lib Library/Frameworks/Mono.framework/Libraries/gac/gtk-dotnet/2.12.0.0__35e10195dab3c99f/gtk-dotnet.dll
-net-lib Library/Frameworks/Mono.framework/Libraries/gac/Mono.Cairo/4.0.0.0__0738eb9f132ed756/Mono.Cairo.dll
-cmd rm bin-mac/bin/atk-sharp.dll
-cmd rm bin-mac/bin/pango-sharp.dll
-cmd rm bin-mac/bin/gdk-sharp.dll
-cmd rm bin-mac/bin/gtk-sharp.dll
-cmd rm bin-mac/bin/glib-sharp.dll
-cmd rm bin-mac/bin/gtk-dotnet.dll
-cmd rm bin-mac/bin/Mono.Cairo.dll
-cmd cd bin-mac/bin/
-cmd mono Main.exe
But this fails at runtime because we also need to link the dylib files associated with some of these dll normally defined in xml next to the dll. like perhaps these:
dllmap os="osx" dll="libgtk-win32-2.0-0.dll" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libgtk-quartz-2.0.0.dylib"
dllmap os="osx" dll="glibsharpglue-2" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libglibsharpglue-2.so"
dllmap os="osx" dll="libgthread-2.0-0" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libgthread-2.0.0.dylib"
dllmap os="osx" dll="libgthread-2.0-0.dll" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libgthread-2.0.0.dylib"
dllmap os="osx" dll="libglib-2.0-0.dll" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libglib-2.0.0.dylib"
dllmap os="osx" dll="libgobject-2.0-0.dll" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libgobject-2.0.0.dylib"
( had to remove xml wrappers as text was not showing )
So my question is could the hxcs haxelib automatically handle these config.dll files found next to the dll's or can you explain the best approach, I would not be so keen on adding global variables to the system to achieve this as they may not be transferable between platforms although that seems a solution mentioned but some clarity in respect of haxe would be useful if this is the approach ( perhaps what is required for the linked project of Jonas above ).
Sorry if doing this dylib stuff is considered easy, but I think it would be nice to add documentation or atleast have some git examples in the wild.
Many thanks Justin
I hope modify csproj that created by "writeProject()".
then call msbuild
CSharpCompiler::compile
code may like
this.data = data;
preProcess();
if (!FileSystem.exists("bin"))
FileSystem.createDirectory("bin");
findCompiler();
writeProject();
if(**manualCompile**) {
return;
}
Whether to consider supporting?
if you switch to -D net-ver=50 with only a main function you get an error:
C:\HaxeToolkit\haxe\std/cs/Pointer.hx:46: characters 8-75 : You need to define 'unsafe' to be able to use unsafe code in hxcs
I think if you don't work with unsafe, you shouldn't have to define unsafe.
The issue may also belong to haxe itself.
This error occurs if hxcs_build.txt grows over the OS command line limit.
In my case it's Windows 7 (32kB max command-line length) and hxcs_build.txt around 67kB.
Tried to shorten the package names, but the file is still well over 32kB...
I have compiled a small hello world to C#: And when compiling using msbuild.exe on windows, it says that it can't find Uri in namespace System.
The .csproj file lacks a reference to system:
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
Don't know why. Maybe System should be included always. mscorlib is the only library that is included by default at least with the Microsoft build tools.
Very useful meta tag for HUGS library http://docs.unity3d.com/Documentation/ScriptReference/HideInInspector.html
C# interfaces can not contain variables: only methods.
There is no any warnings of errors: hxcs just ignores all of it, and all of it's uages. There is no warnings of error messages
I cannot reproduce this locally:
> haxe -cs bin/cs/ -lib travix -lib mithril tests.hxml
haxelib run hxcs hxcs_build.txt --haxe-version 3407 --feature-level 1
Note: dmcs is deprecated, please use mcs instead!
src/buddy/Should.cs(829,84): error CS1525: Unexpected symbol `<'
src/buddy/Should.cs(829,130): error CS1525: Unexpected symbol `('
src/buddy/Should.cs(971,254): error CS1525: Unexpected symbol `<'
src/buddy/Should.cs(971,254): error CS1525: Unexpected symbol `)', expecting `;' or `}'
src/buddy/Should.cs(971,254): error CS1525: Unexpected symbol `,', expecting `;' or `}'
src/buddy/Should.cs(971,254): error CS1525: Unexpected symbol `,', expecting `;' or `}'
src/buddy/Should.cs(971,254): error CS1525: Unexpected symbol `)', expecting `;' or `}'
src/buddy/Should.cs(977,254): error CS1525: Unexpected symbol `>'
src/buddy/Should.cs(977,254): error CS1525: Unexpected symbol `)', expecting `;' or `}'
src/buddy/Should.cs(977,254): error CS1525: Unexpected symbol `,', expecting `;' or `}'
src/buddy/Should.cs(977,254): error CS1525: Unexpected symbol `,', expecting `;' or `}'
src/buddy/Should.cs(977,254): error CS1525: Unexpected symbol `)', expecting `;' or `}'
src/buddy/Should.cs(1318,28): error CS1525: Unexpected symbol `<'
src/buddy/Should.cs(1318,54): error CS1525: Unexpected symbol `<'
src/buddy/Should.cs(1320,9): error CS1525: Unexpected symbol `ShouldIterable', expecting `class', `delegate', `enum', `interface', `partial', or `struct'
src/buddy/Should.cs(1320,54): error CS1525: Unexpected symbol `empty'
src/buddy/Should.cs(1320,103): error CS1525: Unexpected symbol `)'
src/buddy/Should.cs(1324,9): error CS1525: Unexpected symbol `ShouldIterable', expecting `class', `delegate', `enum', `interface', `partial', or `struct'
Compilation failed: 18 error(s), 0 warnings
Compilation error
Native compilation failed
The whole build is here: https://travis-ci.org/ciscoheat/mithril-hx/jobs/374918804#L1912-L1933
Hey :). I'm a new and ardent fan of Haxe, although a bit rusty when it comes to coding since I'm coming after a ~4 years break.
I'm working on a game logic engine. In an ideal world, I'd like to be able to write it entirely in Haxe and developers can integrate it into their target languages by directly including Haxe generated code. In order for this to be as smooth as possible, it is of course desirable that the Haxe output uses as many of the features of the target language as possible and that the code is as clean as possible.
That being said...
C# also supports constraints:
Do you think it would be possible to have this feature of the C# language used in the intermediary Haxe C# output?
Note: from what I know so far, Haxe also supports constraints for functions, whereas C# support stops at the new() function. I am aware that in such case it would probably be hard to transpile Haxe to C#, but perhaps an interface could be generated to satisfy the function constraints?
I am trying to use an external DLL library, my hxml file looks like this
-main Main
-cp src/
--net-lib C:/Windows/System32/zkemkeeper.dll
-cs bin/ZKTDemo
Main.hx
package ;
class Main {
public static function main() {
new Main();
}
public function new() {
var zkeClass = new zkemkeeper.CZKEMClass();
trace(zkeClass);
}
}
I get this error
PeReader.Error_message("This PE file does not have managed content")
I've done an example and write up here: https://github.com/lpetre/tripping-avenger/tree/master
A protected setter on a C# property makes hxcs/net-lib generate invalid C#:
This:
trace(test.Working);
trace(test.Broken);
Becomes:
global::haxe.Log.trace.__hx_invoke2_o(((double) (test.Working) ), global::haxe.lang.Runtime.undefined, default(double), new global::haxe.lang.DynamicObject(new int[]{302979532, 1547539107, 1648581351}, new object[]{"main", "Main", "Main.hx"}, new int[]{1981972957}, new double[]{((double) (7) )}));
global::haxe.Log.trace.__hx_invoke2_o(((double) (test.get_Broken()) ), global::haxe.lang.Runtime.undefined, default(double), new global::haxe.lang.DynamicObject(new int[]{302979532, 1547539107, 1648581351}, new object[]{"main", "Main", "Main.hx"}, new int[]{1981972957}, new double[]{((double) (8) )}));
test.get_Broken() fails to compile with the error:
error CS0571: `Test.Broken.get': cannot explicitly call operator or accessor
When running on Windows, generated C# code breaks non-ASCII input on Windows console.
var s : String = stdin.readLine();
trace("You typed: " + s);
is translated to:
global::haxe.io.Input stdin = global::Sys.stdin();
string s4 = stdin.readLine();
I have not debugged it deeply and have not discovered what and where exactly it goes wrong, but when I type some non-ASCII, e.g. привет
, it spoils my input.
Sys.stdout().writeString(...)
also breaks encoding.
As far as I briefly looked into the code, when writing a string, it encodes it as UTF-8 (which itself is very good, but not compatible with Windows =)). When reading a string, it barely creates characters from stdin
bytes (which is neither compatible with Windows nor good =)).
Both trace
and Sys.println
work well (as expcted, because they do not attempt to perform low-level conversions theirselves).
Nearly same problem is for Java target.
This can be overall design issue of Haxe, in this case sorry for disturbing (and will be glad to know how to work it around =)).
Following the tutorial on the website to create a simple helloworld, I failed, and after looking through the related issues and PRs I finally got it transpiled, but still the generated project csproj file was in the old Visual Studio dependant style, which is certainly not working with .NET Core SDK building. I realized hxcs not supporting .NET Core yet.
But note that .NET Framework has been archived with its final version 4.8, then .NET Core (will be called '.NET' version 5 in the future) becomes the unique officially supported .NET implementation. Therefore by a certain day in the future, not supporting .NET Core equals to not supporting .NET.
As most companies have turned to use .NET Core, abandoning .NET Framework in their new projects, not supporting .NET Core is a critical reason that they would not take Haxe for their .NET stacks.
Thus I do think hxcs should pay all attention to support .NET Core, or Haxe would be no longer taken as a language that targets .NET.
class Test extends haxe.unit.TestCase {
static function main() {
var runner = new haxe.unit.TestRunner();
runner.add(new Test());
runner.run();
}
function testUtf8Compare() {
assertEquals(1, haxe.Utf8.compare("a", "A")); // returns -1 on C#, 1 on other targets
assertEquals(-1, haxe.Utf8.compare("A", "a")); // returns 1 on C#, -1 on other targets
}
}
Tested with Mono 4.2.3 and HXCS 2.3.0 on Haxe 3.3.0RC1
after targeting C#, all fields initializations are moved into class's constuctor, and puts after calling constructor of super class. In most of all cases it;s fine, but here is onle example, that will not work:
class b {}
class a extends b {public var test:Int = 1;}
If class b represents some kind of deserializator (from json-type string, for example), it will initialize some fields, implemented in class a, using reflection.
so:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.