Open EliteMasterEric opened 11 months ago
My guess is that the core issue relates to an assumption somewhere that haxe.root.Array
is where the class will be located.
However, since I can't apply shading after compilation and I can't NOT apply shading (or else the application will simply fail to start when trying to load two Minecraft mods created with my mod framework at the same time), it needs to be done during compilation.
Since reworking the code for the case where this specific annotation breaks things, a general purpose argument to shade the haxe package might be helpful.
Will note here that several cases where I attempted to apply my shading failed, including several typedef
s in my own classes, as well as haxe.jvm.ClosureDispatch
, haxe.jvm.Function
, and haxe.jvm.VarArgs
, among others. These all had @:native
applied to them, but the values were simply ignored. May warrant a new issue if it's not resolved as a side effect to this one.
Yes, haxe.root
and haxe.jvm
are hardcoded in the generator, so if you mess it up via @:native
things are going to break. This also applies to the Type
API which makes some assumptions in that regard.
I'm not sure how to approach this. Something like https://github.com/HaxeFoundation/haxe-evolution/pull/108 would be a very general solution, but then you could still use @:native
to mess everything up.
A feature like HaxeFoundation/haxe-evolution#108 would directly solve my problem, both the main one and the secondary ones found in my comment (while making my shading library obsolete as a consequence ehe, I don't mind tho).
Applying the @:native
annotation to a core Haxe class would still break stuff, but I don't see any reason why you would do that if shading was a feature, it would just break. Basically that one meme where the guy shoves the metal rod into the spokes of his own bike.
I'm not sure if this is really in-scope of a compiler though. Shouldn't there be Java tools that handle this kind of stuff at bytecode-level? Haxe's output works well enough as a compilation unit, and anything beyond that gets very complicated very quickly.
The only reason I'm entertaining this idea at all is because it's already necessary to map the empty package to haxe.root
. Generalizing this could be good, but at the same time it's a quite specific case which needs support in multiple areas. As mentioned, we need to deal with the cases in https://github.com/HaxeFoundation/haxe/blob/development/std/jvm/_std/Type.hx#L103 (look for haxe.root
), so if anything I feel like a specific -D jvm.root=different.package
would make sense here.
The issues here are fairly specific to my use case but basically unavoidable. There are methods to load JARs without causing conflicts. One Minecraft modding framework seems to use this method, but the other one doesn't, and the latter is more popular and I am not in a position to change it.
I don't know of any tools which can perform shading on compiled classes. The one tool I was using previously was operating on the Java sources, and had many issues because it was basically performing a regex find-and-replace.
A specific -D jvm.root=<package>
might make sense, since Java is the only language I can think of where this type of classpath conflict can occur.
I am curious as to how work on resolving this issue has been progressing, since it is a blocker on implementing support for Forge.
I'll have to look into implementing this. I'm not sure how the compiler should communicate to the run-time what the root path is. I guess it could generate some generic haxe.jvm.CompilerInfos
class which has the information as static fields. That doesn't seem very elegant, but maybe it's effective.
Background
I am currently working on a Haxe library to apply shading to a targeted package or module. The modules the macro is applied to should be generated at a new location of the user's choice.
For example,
--macro haxe.shade.Shade.applyPackage("test", "foo.bar")
will causesrc/test/CoolClass.hx
to generate asfoo.bar.CoolClass
, rather thantest.CoolClass
.This is being developed for a Minecraft modding project I am working on, where, if multiple JARs contain conflicting classpaths, the application will fail to load. Since this includes any modules in the
haxe
package, this has been a focus of my development for this library.The module functions by applying the
@:native
metadata to the class, and removing any existing instances of that metadata to avoid overlap.Note this library was originally in the form of a Haxe feature proposal from April of this year. The library is now in development after my project's switch to the JVM target (made possible by the resolution of #11023) mandated that shading no longer be done by Gradle.
The Issue
I am trying to move the
haxe.root.Array
module such that it is generated in the location of my choice, sayfoo.bar.haxe.Array
.Upon applying the macro, I receive this error:
Reproduction
Download the library, use
haxelib dev
to install as a library, then compile./test/issue-11361/compile.hxml
, and see the error.