Browse Source

[hlc] Fix identifier conflicts with windows.h macros (#12335)

* [hlc] Move hlc_main.c #include below source files

hlc_main.c includes windows.h, which defines macros that can conflict
with user code. By placing it below the source file includes, we avoid
this being an issue.

Note, this has to be combined with the hashlink patch to remove
windows.h from hl.h to have any benefit.

* [tests] Check hlc variable with windows.h conflict

SOCKET_ERROR is currently not handled explicitly by hlc.h, so if hl.h
includes windows.h or hlc_main.c comes above generated source files then
the haxe variable name will conflict with the C define.

* [tests] Add HASHLINK define for hlc tests

The vs2022 template requires HASHLINK rather than HASHLINK_SRC/BIN

* [tests] Fix hlc identifier conflict test on non-windows

* [tests] Use x86_64 for hlc misc tests

* [ci] Fix haxe via rosetta during mac testing
tobil4sk 2 months ago
parent
commit
cfc1ced0f0

+ 2 - 5
.github/workflows/main.yml

@@ -799,7 +799,7 @@ jobs:
     needs: mac-build-universal
     runs-on: macos-latest
     env:
-      PLATFORM: mac-arm64
+      PLATFORM: mac-universal
       TEST: ${{matrix.target}}
       HXCPP_COMPILE_CACHE: ~/hxcache
       HAXE_STD_PATH: /usr/local/share/haxe/std
@@ -814,10 +814,7 @@ jobs:
           submodules: recursive
       - uses: actions/download-artifact@v4
         with:
-          # install the arm64-only binaries for HL to avoid issues with Rosetta
-          # the sys tests invoke Haxe, which invokes haxelib, which requires neko
-          # invoking the universal version of haxelib from an x86_64 process fails because neko is arm64-only
-          name: ${{ matrix.target == 'hl' && 'macArmBinaries' || 'macBinaries' }}
+          name: macBinaries
           path: macBinaries
 
       - name: Install Neko from S3

+ 2 - 5
extra/github-actions/workflows/main.yml

@@ -452,7 +452,7 @@ jobs:
     needs: mac-build-universal
     runs-on: macos-latest
     env:
-      PLATFORM: mac-arm64
+      PLATFORM: mac-universal
       TEST: ${{matrix.target}}
       HXCPP_COMPILE_CACHE: ~/hxcache
       HAXE_STD_PATH: /usr/local/share/haxe/std
@@ -467,10 +467,7 @@ jobs:
           submodules: recursive
       - uses: actions/download-artifact@v4
         with:
-          # install the arm64-only binaries for HL to avoid issues with Rosetta
-          # the sys tests invoke Haxe, which invokes haxelib, which requires neko
-          # invoking the universal version of haxelib from an x86_64 process fails because neko is arm64-only
-          name: ${{ matrix.target == 'hl' && 'macArmBinaries' || 'macBinaries' }}
+          name: macBinaries
           path: macBinaries
 
       @import install-neko-unix.yml

+ 2 - 1
src/generators/hl2c.ml

@@ -1923,12 +1923,13 @@ let write_c com file (code:code) gnames num_domains =
 	let line = linec ctx and expr = exprc ctx and sline fmt = Printf.ksprintf (linec ctx) fmt and sexpr fmt = Printf.ksprintf (exprc ctx) fmt in
 	define ctx "#define HLC_BOOT";
 	define ctx "#include <hlc.h>";
-	line "#include <hlc_main.c>";
 	line "";
 	line "#ifndef HL_MAKE";
 	List.iter (sline "#  include <%s>") gctx.cfiles;
 	line "#endif";
 	line "";
+	line "#include <hlc_main.c>";
+	line "";
 	expr "void hl_init_hashes()";
 	expr "void hl_init_roots()";
 	expr "void hl_init_types( hl_module_context *ctx )";

+ 9 - 0
tests/misc/hl/projects/Issue11419/Main.hx

@@ -0,0 +1,9 @@
+/**
+	"SOCKET_ERROR" is reserved as a macro in windows.h, but hopefully our
+	code shouldn't be affected.
+**/
+final SOCKET_ERROR = "SOCKET_ERROR";
+
+function main() {
+	trace(SOCKET_ERROR);
+}

+ 2 - 0
tests/misc/hl/projects/Issue11419/compile.hxml

@@ -0,0 +1,2 @@
+--main Main
+--hl out/main.c

+ 3 - 3
tests/misc/src/Main.hx

@@ -14,7 +14,7 @@ typedef Result = {
 
 class Main {
 	static public function main() {
-		var result:Result = compileProjects();
+		var result:Result = compileProjects(Sys.args());
 		Sys.println('Done running ${result.count} tests with ${result.failures} failures');
 		if(result.count > 20 && result.failures > 0) {
 			Sys.println('SUMMARY:');
@@ -23,7 +23,7 @@ class Main {
 		Sys.exit(result.failures);
 	}
 
-	static public function compileProjects():Result {
+	static public function compileProjects(args:Array<String>):Result {
 		var count = 0;
 		var failures = 0;
 		var failuresSummary = [];
@@ -47,7 +47,7 @@ class Main {
 					var expectFailure = file.endsWith("-fail.hxml");
 					var expectStdout = if (FileSystem.exists('$file.stdout')) prepareExpectedOutput(File.getContent('$file.stdout')) else null;
 					var expectStderr = if (FileSystem.exists('$file.stderr')) prepareExpectedOutput(File.getContent('$file.stderr')) else null;
-					var result = runCommand("haxe", ["-D", "message.reporting=classic", file], expectFailure, expectStdout, expectStderr);
+					var result = runCommand("haxe", ["-D", "message.reporting=classic", file].concat(args), expectFailure, expectStdout, expectStderr);
 					++count;
 					if (!result.success) {
 						failures++;

+ 8 - 1
tests/runci/targets/Hl.hx

@@ -75,6 +75,7 @@ class Hl {
 
 		haxelibDev("hashlink", '$hlSrc/other/haxelib/');
 
+		Sys.putEnv("HASHLINK", hlInstallDir);
 		if (systemName == "Windows") {
 			Sys.putEnv("HASHLINK_SRC", hlSrc);
 			Sys.putEnv("HASHLINK_BIN", hlInstallBinDir);
@@ -167,6 +168,12 @@ class Hl {
 		buildAndRun("compile.hxml", "bin/reservedKeywords");
 
 		changeDirectory(miscHlDir);
-		runCommand("haxe", ["run.hxml"]);
+		if (systemName == "Windows") {
+			runCommand("haxe", ["run.hxml", "-D", "hlgen.makefile=vs2022"]);
+		} else if (systemName == "Mac") {
+			runCommand("arch", ["-x86_64", "haxe", "run.hxml", "-D", "hlgen.makefile=make"]);
+		} else {
+			runCommand("haxe", ["run.hxml", "-D", "hlgen.makefile=make"]);
+		}
 	}
 }