implement name for executables
This commit is contained in:
parent
76332f5ad7
commit
070baf4599
@ -41,6 +41,7 @@ const installation_dir_name = "installation";
|
|||||||
|
|
||||||
const ArgumentParsingError = error{
|
const ArgumentParsingError = error{
|
||||||
main_package_path_not_specified,
|
main_package_path_not_specified,
|
||||||
|
main_source_file_not_found,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn reportUnterminatedArgumentError(string: []const u8) noreturn {
|
fn reportUnterminatedArgumentError(string: []const u8) noreturn {
|
||||||
@ -57,6 +58,7 @@ fn parseArguments(compilation: *const Compilation) !Compilation.Module.Descripto
|
|||||||
var should_transpile_to_c: ?bool = null;
|
var should_transpile_to_c: ?bool = null;
|
||||||
var maybe_only_parse: ?bool = null;
|
var maybe_only_parse: ?bool = null;
|
||||||
var link_libc = false;
|
var link_libc = false;
|
||||||
|
var maybe_executable_name: ?[]const u8 = null;
|
||||||
|
|
||||||
if (arguments.len == 0) {
|
if (arguments.len == 0) {
|
||||||
// foo
|
// foo
|
||||||
@ -165,8 +167,26 @@ fn parseArguments(compilation: *const Compilation) !Compilation.Module.Descripto
|
|||||||
} else {
|
} else {
|
||||||
reportUnterminatedArgumentError(current_argument);
|
reportUnterminatedArgumentError(current_argument);
|
||||||
}
|
}
|
||||||
|
} else if (equal(u8, current_argument, "-main_source_file")) {
|
||||||
|
if (i + 1 != arguments.len) {
|
||||||
|
i += 1;
|
||||||
|
|
||||||
|
const arg = arguments[i];
|
||||||
|
maybe_main_package_path = arg;
|
||||||
|
} else {
|
||||||
|
reportUnterminatedArgumentError(current_argument);
|
||||||
|
}
|
||||||
|
} else if (equal(u8, current_argument, "-name")) {
|
||||||
|
if (i + 1 != arguments.len) {
|
||||||
|
i += 1;
|
||||||
|
|
||||||
|
const arg = arguments[i];
|
||||||
|
maybe_executable_name = arg;
|
||||||
|
} else {
|
||||||
|
reportUnterminatedArgumentError(current_argument);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
maybe_main_package_path = current_argument;
|
std.debug.panic("Unrecognized argument: {s}", .{current_argument});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +197,12 @@ fn parseArguments(compilation: *const Compilation) !Compilation.Module.Descripto
|
|||||||
const only_parse = maybe_only_parse orelse false;
|
const only_parse = maybe_only_parse orelse false;
|
||||||
|
|
||||||
var is_build = false;
|
var is_build = false;
|
||||||
const main_package_path = if (maybe_main_package_path) |path| path else blk: {
|
const main_package_path = if (maybe_main_package_path) |path| blk: {
|
||||||
|
const file = std.fs.cwd().openFile(path, .{}) catch return error.main_source_file_not_found;
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
break :blk path;
|
||||||
|
} else blk: {
|
||||||
const build_file = "build.nat";
|
const build_file = "build.nat";
|
||||||
const file = std.fs.cwd().openFile(build_file, .{}) catch return error.main_package_path_not_specified;
|
const file = std.fs.cwd().openFile(build_file, .{}) catch return error.main_package_path_not_specified;
|
||||||
file.close();
|
file.close();
|
||||||
@ -187,7 +212,12 @@ fn parseArguments(compilation: *const Compilation) !Compilation.Module.Descripto
|
|||||||
};
|
};
|
||||||
|
|
||||||
const executable_path = maybe_executable_path orelse blk: {
|
const executable_path = maybe_executable_path orelse blk: {
|
||||||
const executable_name = if (is_build) "build" else std.fs.path.basename(main_package_path[0 .. main_package_path.len - "/main.nat".len]);
|
const executable_name = if (is_build) b: {
|
||||||
|
assert(maybe_executable_name == null);
|
||||||
|
break :b "build";
|
||||||
|
} else b: {
|
||||||
|
break :b if (maybe_executable_name) |name| name else std.fs.path.basename(main_package_path[0 .. main_package_path.len - "/main.nat".len]);
|
||||||
|
};
|
||||||
assert(executable_name.len > 0);
|
assert(executable_name.len > 0);
|
||||||
const result = try std.mem.concat(allocator, u8, &.{ "nat/", executable_name });
|
const result = try std.mem.concat(allocator, u8, &.{ "nat/", executable_name });
|
||||||
break :blk result;
|
break :blk result;
|
||||||
|
4
ci.sh
4
ci.sh
@ -26,7 +26,7 @@ nat_compiler=$my_current_directory/zig-out/bin/nat
|
|||||||
for standalone_test_case in $standalone_test_directory_files
|
for standalone_test_case in $standalone_test_directory_files
|
||||||
do
|
do
|
||||||
STANDALONE_TEST_NAME=${standalone_test_case##*/}
|
STANDALONE_TEST_NAME=${standalone_test_case##*/}
|
||||||
$nat_compiler $standalone_test_case/main.nat
|
$nat_compiler -main_source_file $standalone_test_case/main.nat
|
||||||
|
|
||||||
if [[ "$?" == "0" ]]; then
|
if [[ "$?" == "0" ]]; then
|
||||||
passed_compilation_count=$(($passed_compilation_count + 1))
|
passed_compilation_count=$(($passed_compilation_count + 1))
|
||||||
@ -66,7 +66,7 @@ do
|
|||||||
if [[ "$?" == "0" ]]; then
|
if [[ "$?" == "0" ]]; then
|
||||||
passed_compilation_count=$(($passed_compilation_count + 1))
|
passed_compilation_count=$(($passed_compilation_count + 1))
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
nat/src
|
nat/$MY_TESTNAME
|
||||||
|
|
||||||
if [[ "$?" == "0" ]]; then
|
if [[ "$?" == "0" ]]; then
|
||||||
passed_test_count=$(($passed_test_count + 1))
|
passed_test_count=$(($passed_test_count + 1))
|
||||||
|
@ -10,6 +10,7 @@ const main = fn () s32 {
|
|||||||
.abi = .gnu,
|
.abi = .gnu,
|
||||||
},
|
},
|
||||||
.main_source_path = "src/main.nat",
|
.main_source_path = "src/main.nat",
|
||||||
|
.name = "exe",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (executable.compile()) {
|
if (executable.compile()) {
|
||||||
|
@ -7,6 +7,7 @@ const Executable = struct{
|
|||||||
target: Target,
|
target: Target,
|
||||||
main_source_path: [:0]const u8,
|
main_source_path: [:0]const u8,
|
||||||
link_libc: bool = false,
|
link_libc: bool = false,
|
||||||
|
name: []const u8,
|
||||||
|
|
||||||
const compile = fn(executable: Executable) bool {
|
const compile = fn(executable: Executable) bool {
|
||||||
const argument_count = std.start.argument_count;
|
const argument_count = std.start.argument_count;
|
||||||
@ -21,7 +22,7 @@ const Executable = struct{
|
|||||||
const compile_with_compiler_path = fn(executable: Executable, compiler_path: [&:0]const u8) bool {
|
const compile_with_compiler_path = fn(executable: Executable, compiler_path: [&:0]const u8) bool {
|
||||||
if (std.os.duplicate_process()) |pid| {
|
if (std.os.duplicate_process()) |pid| {
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
const argv = [_:null] ?[&:0]const u8{ compiler_path, #cast(executable.main_source_path.ptr), "-link_libc", if (executable.link_libc) "true" else "false"};
|
const argv = [_:null] ?[&:0]const u8{ compiler_path, "-main_source_file", #cast(executable.main_source_path.ptr), "-link_libc", if (executable.link_libc) "true" else "false", "-name", #cast(executable.name.ptr) };
|
||||||
std.os.execute(path = compiler_path, argv = argv.&, env = std.start.environment_values);
|
std.os.execute(path = compiler_path, argv = argv.&, env = std.start.environment_values);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -352,6 +352,23 @@ const waitpid = fn(pid: Process.Id, flags: u32) ?u32 {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const memfd_create = fn(name: [&:0]const u8, flags: u32) ?FileDescriptor{
|
||||||
|
switch (current) {
|
||||||
|
.linux => {
|
||||||
|
if (linux.unwrapSyscall(syscall_result = linux.memfd_create(path, flags))) |raw_result| {
|
||||||
|
const file_descriptor = FileDescriptor{
|
||||||
|
.handle = #cast(raw_result),
|
||||||
|
};
|
||||||
|
|
||||||
|
return file_descriptor;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
else => #error("OS not supported"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const IoChannelBehavior = enum{
|
const IoChannelBehavior = enum{
|
||||||
pipe,
|
pipe,
|
||||||
close,
|
close,
|
||||||
|
@ -485,6 +485,11 @@ const poll = fn(file_descriptors: [&]PollFileDescriptor, file_descriptor_count:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const memfd_create = fn(name: [&:0]const u8, flags: u32) usize {
|
||||||
|
const result = #syscall(#cast(Syscall.memfd_create), flags);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
const unwrapSyscall = fn(syscall_result: usize) ?usize {
|
const unwrapSyscall = fn(syscall_result: usize) ?usize {
|
||||||
const signed_syscall_result: ssize = #cast(syscall_result);
|
const signed_syscall_result: ssize = #cast(syscall_result);
|
||||||
if (signed_syscall_result >= 0) {
|
if (signed_syscall_result >= 0) {
|
||||||
|
@ -10,6 +10,7 @@ const main = fn () s32 {
|
|||||||
.abi = .gnu,
|
.abi = .gnu,
|
||||||
},
|
},
|
||||||
.main_source_path = "src/main.nat",
|
.main_source_path = "src/main.nat",
|
||||||
|
.name = "first",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (executable.compile()) {
|
if (executable.compile()) {
|
||||||
|
@ -11,6 +11,7 @@ const main = fn () s32 {
|
|||||||
},
|
},
|
||||||
.main_source_path = "src/main.nat",
|
.main_source_path = "src/main.nat",
|
||||||
.link_libc = true,
|
.link_libc = true,
|
||||||
|
.name = "link_libc",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (executable.compile()) {
|
if (executable.compile()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user