HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.21k stars 658 forks source link

Target configuration from command line #6582

Closed Simn closed 10 months ago

Simn commented 7 years ago

The idea is to add a command line flag which allows specifying a custom target name, e.g. -custom xyz. This then does the following:

  1. Set our internal target value to Custom("xyz"). This causes the standard library identifier to be xyz, so users can implement their own things there.
  2. Look for a xyz.json (or some other convention) in the class path. This file contains a convention for the target configuration, such as { "static": true, padNull: false }.
ibilon commented 7 years ago

I had a similar idea :) The difference is I thought of something like -custom SomeClass or -custom path/SomeClass.hx with all the configuration in the class, read with eval maybe? Detail though.

Simn commented 7 years ago

The problem is that want to set the target value really early, and booting up the macro engine might cause something in the target context before the macro is executed. That's why I want to just have a dumb command line configuration and then take it from there.

ncannasse commented 7 years ago

I would go with something more advanced/explicit, such as --custom-target xyz

On Sat, Sep 16, 2017 at 11:19 PM, Simon Krajewski notifications@github.com wrote:

The problem is that want to set the target value really early, and booting up the macro engine might cause something in the target context before the macro is executed. That's why I want to just have a dumb command line configuration and then take it from there.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/haxe/issues/6582#issuecomment-329995520, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-bwJSgyBd6_Dt0q5vmVhgbymW23ig_ks5sjDtfgaJpZM4PZusk .

Simn commented 7 years ago

How about -target?

That reminds me we still have to specify the output file/path somehow.

ncannasse commented 7 years ago

Given that it's mostly for experimental things, I insist of having a long name + starting with two dashes :)

On Mon, Sep 18, 2017 at 5:28 PM, Simon Krajewski notifications@github.com wrote:

How about -target?

That reminds me we still have to specify the output file/path somehow.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/haxe/issues/6582#issuecomment-330260127, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-bwF2NxKBKuGDX7jyAmG4FwJI6qf0Yks5sjowmgaJpZM4PZusk .

ibilon commented 7 years ago

The number of dashes should really be coherent on all arguments.

Simn commented 7 years ago

Given that it's mostly for experimental things, I insist of having a long name + starting with two dashes :)

Could you start drinking some beer again so you're making more sense? :)

Aurel300 commented 7 years ago

How does this affect the generator used? E.g. if I do

-js out.js
-target xyz

It still uses the js generator but … Uses a different std namespace?

Simn commented 7 years ago

That should probably fail with "multiple targets".

Aurel300 commented 7 years ago

Correct me if I'm wrong, but having a JSON which says whether a target is static or not + std library implementation is not the same as specifying a custom generator.

By the way, being able to specify a custom generator would be amazing and it should be in Haxe 😢

Simn commented 7 years ago

You can implement whatever funky generator you want using onGenerate. The only problem with that was that you couldn't configure the target and had to somehow re-use an existing stdlib.

fullofcaffeine commented 7 years ago

When you're talking about onGenerate, you're essentially talking about the CustomJSGen, right? Shouldn't we rename that to more general btw, since any generator for any language can be implemented using it?

Also, as a side question, is it already possible to create custom generators in OCaml and load them as plugins?

On Thu, Sep 21, 2017 at 8:14 AM, Simon Krajewski notifications@github.com wrote:

You can implement whatever funky generator you want using onGenerate. The only problem with that was that you couldn't configure the target and had to somehow re-use an existing stdlib.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/haxe/issues/6582#issuecomment-331152511, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE9YFnmoSdvlUrTohepVDLW0bha26OTks5skmElgaJpZM4PZusk .

Simn commented 7 years ago

When I'm talking about onGenerate, I'm talking about onGenerate.

And yeah you can probably build an OCaml generator using eval.vm.Context.loadPlugin (which as I've just noticed doesn't show up on api.haxe.org for some reason). That feature is pretty experimental though and probably requires some bugfixes.

Simn commented 7 years ago

I just tried it because I was curious. Here's what I did:

  1. Place this file in haxe/jsgen.ml:
open EvalValue
open EvalEncode
open EvalContext
open MacroApi

let generate () =
    let com = (get_ctx()).curapi.get_com() in
    Genjs.generate com;
    vnull
;;
EvalStdLib.StdContext.register ["generate",vfun0 generate]
  1. Generate plugin: make PLUGIN=jsgen plugin

  2. Copy jsgen.cmxs to Haxe project.

  3. Use this Main.hx file:

class Main {
    static public function main() {
        register();
    }

    macro static function register() {
        var plugin = eval.vm.Context.loadPlugin("jsgen.cmxs");
        haxe.macro.Context.onGenerate(_ -> plugin.generate());
        return macro null;
    }
}
  1. Compile it with haxe -cp src -main Main -js test.js --no-output

That gave me a test.js file as expected. The --no-output is just there so the real generator isn't run.

back2dos commented 6 years ago

7576 reminded me of this. Will this require any breaking changes?

My suggestion would be to make the target configuration purely via command line arguments. In the end a custom target can be shipped as a lib that sets all the compiler flags it needs (in extraParams.hxml) and you can just go haxe -lib hxdart -main Main -D output=yay.dart

Simn commented 5 years ago

Some thoughts:

Simn commented 10 months ago

This was closed in #11128.