Giter VIP home page Giter VIP logo

hlc-compiler-sample's Introduction

hlc-compiler-sample

A small example of HashLink/C native compilation using hlc-compiler.

The example project to be compiled uses Heaps.io.

Prerequisites

Important ones

  • Haxe 4.2.3 or compatible
  • HashLink 1.11.0 or compatible
  • C compiler
    • Windows: GCC 11.2.0 or compatible
    • Mac: Clang 13.1.6 or compaptible

lix (optional; not required)

lix is an alternative package manager for Haxe projects.

If you aren't using lix, you can ignore the following files in this repository:

  • .haxerc
  • haxe_libraries/

Haxe library dependencies

  • For targeting HashLink:
  • For use in the example project:
  • For compiling HL/C into executable:

To install:

haxelib newrepo
haxelib install hashlink
haxelib install heaps
haxelib install hlsdl
haxelib install hldx
haxelib install hlc-compiler

Or, if using lix, just:

lix download

Usage

Compile Haxe -> HL/C

Run Haxe with:

haxe hxml/build-hl-c.hxml

This will:

  1. compile the example source code in src/, and
  2. generate HL/C code in the out/c/ directory.

Compile HL/C -> executable

Run the file below, which defines a single commandline for invoking haxelib run hlc-compiler with some options.

  • On Windows: run-hlc-compiler.bat
  • On Mac: run-hlc-compiler.command

This will generate:

  • Executable file (with other runtime files) in the bin/ directory
  • Command file for re-compiling in the out/ directory

One-stop compiling & testing

To run the build processes above at once:

haxe -cp scripts --run Compile

Or, if using lix, just:

lix Compile

See scripts/Compile.hx for what it does.

You may also add optional arguments as below (simply add them to the commandline above):

  • --clean or -c : Cleanup the output directories (out/ and bin/) before the compilation.
  • --test or -t : Runs the generated executable once the compilation completes.

Select libraries to be included

Edit hxml/libraries.hxml to switch/exclude some libraries.

The USE_??? defines have actually no effect in this sample project (see src/Main.hx), but you can see how they affect the compilation result (i.e. what kind of files will be output into bin/) by enabling/disabling them.

Compile a minimum CLI application

To test compiling a minimum CLI app:

  • Replace the entire content of src/Main.hx with a minimized main() function.
    • Such as: function main() Sys.println("Hello world!");
  • Comment out all the lines in hxml/libraries.hxml.
  • Remove unnecessary options for hlc-compiler in the run-hlc-compiler.bat/command file.
    • Such as --runtime and -mwindows

Misc

Errors?

If something goes wrong:

  • Try haxe hxml/test-hl-jit.hxml to test on the HL/JIT target. If it reproduces, perhaps it's not a HL/C issue.
  • Check your Haxe version. Playing sound will not work well with Haxe 4.2.4 or 4.2.5.
  • See also: https://github.com/fal-works/hlc-compiler/wiki

About the sample resource

hlc-compiler-sample's People

Contributors

fal-works avatar

Stargazers

 avatar

Watchers

 avatar

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.