haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Adds a new `--std-path` argument to set standard library path.

Open tritao opened this issue 1 year ago • 2 comments

This PR adds an --std-path argument to set standard library path as an alternative to setting the HAXE_STD_PATH environment variable.

This is useful to be able to use Haxe from the ninja build system, as it does not support setting environment variables from its build scripts: https://github.com/ninja-build/ninja/issues/1002

I have also read that I might need to set HAXELIB_PATH and HAXEPATH to get haxelib working. I quickly checked the source code and the compiler does seem to invoke haxelib in some places, so would it be acceptable to add more flags for those paths? Or is there a better mechanism that could be used as an alternative?

Also this is my first using OCaml and hacking on the compiler to let me know of any issues with the code.

tritao avatar Sep 21 '24 20:09 tritao

Ok, I think some weirdness is happening with the CI.

The Build Haxe build step is green and reported as passing, but its actually failing:

File "src/optimization/dce.ml", line 90, characters 13-48:
90 | 	List.exists (ExtString.String.starts_with file) dce.std_dirs
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type prefix:string -> bool
       but an expression was expected of type 'a -> bool
make: *** [Makefile:81: haxe] Error 1

... and its failing with the error that my other PR fixes: https://github.com/HaxeFoundation/haxe/pull/11779

Some quick search shows that it may need $ErrorActionPreference = 'Stop' there to stop if any command fails.

tritao avatar Sep 21 '24 21:09 tritao

Two things:

  1. We try to avoid magic values like "", so it's better to declare com.std_path as string option and then do (match com.std_path with None -> (* the "" case *) | Some std_path -> (* the other case *)).

  2. This hooks into get_std_class_paths, which is called via setup_common_context, which is called before parse_args (see compile_ctx in compiler.ml). Unless I'm misreading something here I can't see how this implementation actually works timing-wise because com.std_path is set only after it's relevant.

Simn avatar Sep 22 '24 04:09 Simn

This was never updated.

Simn avatar Apr 05 '25 20:04 Simn