Giter Club home page Giter Club logo

hxcs's Introduction

hxcs

TravisCI Build Status

Support library for Haxe C# backend.

It contains a build tool that is called by Haxe, discovering and calling the C# compiler on the C# code generated by Haxe. It also contains .NET 2.0, 4.0, 4.5 and 5.0 core assemblies that contain core .NET types and APIs.

TODO

  • C# CFFI compatibility: be able to use unmodified .ndlls (though recompilation is needed) from hxcpp and neko in C#

hxcs's People

Contributors

8aginski avatar andyli avatar klabz avatar mandel59 avatar nadako avatar realyuniquename avatar sebthom avatar simn avatar waneck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hxcs's Issues

Assembly reference

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.

UWP target. Compilation errors

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

You need to define 'unsafe' to be able to use unsafe code in hxcs in dotnet 5.0

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.

interfaces

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

Using mono compiler on windows?

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..!

A request stop all after writeProject()

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?

.NET 4.5 mscorlib.dll cannot be read.

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)

Extending StringMap not working as expected - CS - copied from Main Haxe Issues

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();
    }
	
}

Windows console unicode input

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 =)).

Utf8.compare() is broken

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

Generic type definition not working fine

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.

Win7: "The command line is too long" problem

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...

Compiling a small program causes a System.Uri not found

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.

Fields initialization

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:

  1. constructor of class 'a' calls constroctor of class 'b'
  2. class 'b' deserializes data, and initializes field 'test' of class 'a'
  3. class 'a' replases data from field 'test' with default '1';

Using msbuild/xbuild instead of directly using C# compilers?

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.

How to define or pass dll "config" information for mac systems?

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

static fields initialization

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.

PeReader.Error_message("This PE file does not have managed content")

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")

.NET Core Support

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.

A protected setter on a property causes hxcs/net-lib to generate invalid C#

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

Properly transpile constraints into C# code?

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:

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/where-generic-type-constraint

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?

Strange native compilation error on travis

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.