Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[neko] Add support for loading arm ndlls #10996

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/generators/genneko.ml
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,14 @@ let generate_libs_init = function
else
"/usr/local/lib/haxe/lib/";
if( try $loader.loadprim("std@sys_file_type",1)(".haxelib") == "dir" catch e false ) @b = $loader.loadprim("std@file_full_path",1)(".haxelib") + "/";
if( $loader.loadprim("std@sys_is64",0)() ) @s = @s + 64;
if( $version() >= 240 )
@s = @s + switch $loader.loadprim("std@sys_cpu_arch",0)() {
"arm64" => "Arm64"
"arm" => "Arm"
"x86_64" => "64"
default => ""
};
else if( $loader.loadprim("std@sys_is64",0)() ) @s = @s + 64;
@b = @b + "/"
*)
let p = null_pos in
Expand Down Expand Up @@ -705,7 +712,14 @@ let generate_libs_init = function
),p);
],p);
(EIf ((ETry (op "==" (call p (loadp "sys_file_type" 1) [str p ".haxelib"]) (str p "dir"),"e",(EConst False,p)),p),op "=" (ident p "@b") (op "+" (call p (loadp "file_full_path" 1) [str p ".haxelib"]) (str p "/")), None),p);
(EIf (call p (loadp "sys_is64" 0) [],op "=" es (op "+" es (int p 64)),None),p);
(EIf (op ">=" (builtin p "version") (int p 240),
(op "=" es (op "+" es (ESwitch (call p (loadp "sys_cpu_arch" 0) [],[
(str p "arm64", str p "Arm64");
(str p "arm", str p "Arm");
(str p "x86_64", str p "64");
], Some (str p "")),p))),
Some (EIf (call p (loadp "sys_is64" 0) [],op "=" es (op "+" es (int p 64)),None),p)
),p);
op "=" es (op "+" es (str p "/"));
] in
let lpath = field p (builtin p "loader") "path" in
Expand Down
70 changes: 70 additions & 0 deletions tests/misc/neko/projects/Issue10937/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import sys.io.Process;

using StringTools;

enum abstract Arch(String) {
final Arm64;
final Arm;
final X86;
final X86_64;

public function getNdllSuffix():String {
return switch abstract {
case Arm64: "Arm64";
case Arm: "Arm";
case X86_64: "64";
case X86: "";
};
}
}

function getArchWindows() {
return switch Sys.getEnv("PROCESSOR_ARCHITECTURE") {
case "x86": X86;
case "AMD64": X86_64;
case "ARM64": Arm64;
case other: throw 'Unknown CPU architecture: $other';
};
}

function getArchUnix() {
final uname = new Process("uname", ["-m"]);

final arch = try {
uname.stdout.readLine();
} catch (e:haxe.io.Eof) {
"";
};

uname.kill();
uname.close();

return switch arch {
case "x86_64" | "amd64": X86_64;
case "i386" | "x86": X86;
case "arm64" | "aarch64": Arm64;
case "arm": Arm;
case other: throw 'Unknown CPU architecture: "$other"';
};
}

function getArch() {
return switch Sys.systemName() {
case "Windows": getArchWindows();
default: getArchUnix();
};
}

function main() {
final arch = getArch();

final expectedNdllSubDir = Sys.systemName() + arch.getNdllSuffix() + "/";

final ndllPath = neko.vm.Loader.local().getPath()[0];

if (ndllPath.endsWith(expectedNdllSubDir)) {
Sys.println("Success");
} else {
Sys.println('Failure: Expected $ndllPath to end with $expectedNdllSubDir');
}
}
1 change: 1 addition & 0 deletions tests/misc/neko/projects/Issue10937/aaa-setup.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--cmd haxelib dev dummy_ndll dummy_ndll
4 changes: 4 additions & 0 deletions tests/misc/neko/projects/Issue10937/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--main Main
--neko bin/main.n
-lib dummy_ndll
--cmd neko bin/main.n
1 change: 1 addition & 0 deletions tests/misc/neko/projects/Issue10937/compile.hxml.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success
Empty file.
2 changes: 2 additions & 0 deletions tests/misc/neko/run.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-cp ../src
--run Main
3 changes: 3 additions & 0 deletions tests/runci/targets/Neko.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Neko {
runCommand("haxe", ["compile-neko.hxml", "-D", "dump", "-D", "dump_ignore_var_ids"].concat(args));
runCommand("neko", ["bin/unit.n"]);

changeDirectory(getMiscSubDir('neko'));
runCommand("haxe", ["run.hxml"].concat(args));

changeDirectory(sysDir);
runCommand("haxe", ["compile-neko.hxml"].concat(args));
runSysTest("neko", ["bin/neko/sys.n"]);
Expand Down