Skip to content

[hlc] Implement automatic compilation with make and Build.xml templates - #706

Merged
yuxiaomao merged 19 commits into
HaxeFoundation:masterfrom
tobil4sk:feature/automatic-compilation
May 6, 2025
Merged

[hlc] Implement automatic compilation with make and Build.xml templates#706
yuxiaomao merged 19 commits into
HaxeFoundation:masterfrom
tobil4sk:feature/automatic-compilation

Conversation

@tobil4sk

@tobil4sk tobil4sk commented Sep 1, 2024

Copy link
Copy Markdown
Member

This adds two new templates to the hashlink support library to simplify hlc compilation: make for a regular Makefile, and hxcpp for a Build.xml. Both of these implement automated compilation, so if you add either of these then an executable is generated automatically:

-D hlgen.makefile=make
-D hlgen.makefile=hxcpp

The Makefile is smart so it will only recompile files whose dependencies have changed. I've tested it on Linux and on Windows with mingw.

Like with the Visual Studio templates, on Windows the templates expect a HASHLINK environment variable to point to the hashlink installation. With the Build.xml template, the installation can also point to the hashlink sources, provided that they contain binaries generated by hl.sln.

Use LDLIBS for passing libraries to the linker:
https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html#index-LDLIBS

Compile .c files into separate .o files to avoid recompiling the entire
project every time. Use .d files to keep track of .c files that
depend on .h files. For reference:
https://stackoverflow.com/a/52036564
For some reason, mingw doesn't like `-I./`, this causes it to be unable
to find the includes
Previously it would always generate them next to the .c files,
regardless of whether hlgen.makefilepath had been set. Now it ensures
that it doesn't write outside of the Makefile directory.

This means that it first has to create the directories, otherwise the
compiler complains about directories not existing when it tries to
write the output files.

".SUFFIXES" also has to be set as an empty target, otherwise the built-
in rules mess up the rule dependencies.
@skial skial mentioned this pull request Sep 4, 2024
1 task
@kLabz

kLabz commented Nov 1, 2024

Copy link
Copy Markdown
Contributor

Small documentation / default value handling issue:

Set hlgen.makefile for automatic native compilation

But adding -D hlgen.makefile (without setting a value) gives:

Automatic native compilation not yet implemented for 1

If picking a default value is not something we want, it would be nice to list correct values in this error message I think?

@tobil4sk

tobil4sk commented Nov 1, 2024

Copy link
Copy Markdown
Member Author

If picking a default value is not something we want, it would be nice to list correct values in this error message I think?

The default value was working before, I just forgot about it with my changes so this should be fixed. Maybe it should be updated though:

  • vs2019 for windows
  • make for other systems

Aside from this, the makefile here doesn't support mac at the moment (mac linker doesn't support -l:fmt.hdll syntax). This will have to be fixed before this can be merged. -lfmt.hdll doesn't work because hdll libraries don't follow the standard naming of lib[name].so. We can instead link with the full path /usr/local/lib/fmt.hdll, however, on linux this hardcodes the full path for loading the library, unless fmt.hdll is built with -soname (already the case with the hashlink cmake file, but not the hashlink make file). So there are two options:

  • Use the full path universally, requiring hdlls (including user-made ones) to be built with -soname on linux.
  • Generate separate linking flags for mac and linux.

@Simn

Simn commented Apr 9, 2025

Copy link
Copy Markdown
Member

Yuxiao made me aware of this PR and I'd like to see this made working. Native compilation is the main difficulty I have with HL/C over hxcpp, where everything mostly "just works". I'm not sure what decisions have to be made here, and who has to make them, so I'll just ping @ncannasse and @yuxiaomao and hope for the best!

@ncannasse

ncannasse commented Apr 9, 2025 via email

Copy link
Copy Markdown
Member

@yuxiaomao

Copy link
Copy Markdown
Collaborator

This PR is ready for me now, with

  • Automatic compilation with make/hxcpp/vs2019/2022 templates
  • Mac uses separate linking flags with absolute path to hdll (tested on a Mac with Rosetta)
  • Suggests default hlgen.makefile value vs2019 (win) / make (others)

If I'm motivated I can eventually add some CI for this with a link to fmt.hdll (e.g. haxe.crypto.Sha1.encode("Hello world"))

@yuxiaomao

Copy link
Copy Markdown
Collaborator

Let's merge this x)

@yuxiaomao
yuxiaomao merged commit 0f3bc39 into HaxeFoundation:master May 6, 2025
@tobil4sk
tobil4sk deleted the feature/automatic-compilation branch May 7, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants