restricted c header imports
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import "./compiler"
|
||||
import "./compiler/cimport"
|
||||
import "./compiler/linker"
|
||||
import "./compiler/target"
|
||||
import "core:fmt"
|
||||
@@ -10,6 +11,7 @@ Cli_Options :: struct {
|
||||
input_path: string,
|
||||
output_path: string,
|
||||
link_arguments: []linker.Argument,
|
||||
c_options: cimport.Options,
|
||||
target: target.Target,
|
||||
}
|
||||
|
||||
@@ -20,13 +22,24 @@ parse_cli_args :: proc(args: []string, allocator := context.allocator) -> (Cli_O
|
||||
options := Cli_Options{input_path=args[1], target=target.DEFAULT}
|
||||
link_arguments: [dynamic]linker.Argument
|
||||
link_arguments.allocator = allocator
|
||||
include_paths: [dynamic]string
|
||||
include_paths.allocator = allocator
|
||||
defines: [dynamic]string
|
||||
defines.allocator = allocator
|
||||
success := false
|
||||
defer {
|
||||
if !success {
|
||||
delete(link_arguments)
|
||||
delete(include_paths)
|
||||
delete(defines)
|
||||
}
|
||||
}
|
||||
output_set := false
|
||||
cursor := 2
|
||||
for cursor < len(args) {
|
||||
option := args[cursor]
|
||||
cursor += 1
|
||||
if cursor >= len(args) {
|
||||
delete(link_arguments)
|
||||
return {}, false
|
||||
}
|
||||
value := args[cursor]
|
||||
@@ -34,40 +47,43 @@ parse_cli_args :: proc(args: []string, allocator := context.allocator) -> (Cli_O
|
||||
switch option {
|
||||
case "-o":
|
||||
if output_set {
|
||||
delete(link_arguments)
|
||||
return {}, false
|
||||
}
|
||||
output_set = true
|
||||
options.output_path = value
|
||||
case "--link":
|
||||
case "--c-link":
|
||||
append(&link_arguments, linker.Argument{kind=.Input, value=value})
|
||||
case "--library-path":
|
||||
case "--c-library-path":
|
||||
append(&link_arguments, linker.Argument{kind=.Library_Path, value=value})
|
||||
case "--library":
|
||||
case "--c-library":
|
||||
append(&link_arguments, linker.Argument{kind=.Library, value=value})
|
||||
case "--c-include-path":
|
||||
append(&include_paths, value)
|
||||
case "--c-define":
|
||||
append(&defines, value)
|
||||
case "--target":
|
||||
selected, ok := target.parse(value)
|
||||
if !ok {
|
||||
delete(link_arguments)
|
||||
return {}, false
|
||||
}
|
||||
options.target = selected
|
||||
case:
|
||||
delete(link_arguments)
|
||||
return {}, false
|
||||
}
|
||||
}
|
||||
if !output_set || len(options.output_path) == 0 {
|
||||
delete(link_arguments)
|
||||
return {}, false
|
||||
}
|
||||
options.link_arguments = link_arguments[:]
|
||||
options.c_options.include_paths = include_paths[:]
|
||||
options.c_options.defines = defines[:]
|
||||
success = true
|
||||
return options, true
|
||||
}
|
||||
|
||||
print_usage :: proc() {
|
||||
fmt.eprintln(
|
||||
"usage: brolang <package-directory> -o <executable> [--target aarch64-macos] [--link <path> | --library-path <dir> | --library <name>]...",
|
||||
"usage: brolang <package-directory> -o <executable> [--target aarch64-macos] [--c-link <path> | --c-library-path <dir> | --c-library <name> | --c-include-path <dir> | --c-define <name[=value]>]...",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -78,7 +94,9 @@ main :: proc() {
|
||||
os2.exit(2)
|
||||
}
|
||||
defer delete(options.link_arguments)
|
||||
status := compiler.compile_package(options.input_path, options.output_path, options.link_arguments, options.target)
|
||||
defer delete(options.c_options.include_paths)
|
||||
defer delete(options.c_options.defines)
|
||||
status := compiler.compile_package(options.input_path, options.output_path, options.link_arguments, options.target, options.c_options)
|
||||
if status != 0 {
|
||||
os2.exit(status)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user