#!/bin/sh
+INSTALL_DIR="/usr"
+
# Where the core libraries for Onyx will go.
-CORE_DIR='/usr/share/onyx'
+CORE_DIR="$INSTALL_DIR/share/onyx"
# Where the onyx executable will be placed.
-BIN_DIR='/usr/bin'
+BIN_DIR="$INSTALL_DIR/bin"
ARCH="$(uname -m)"
compile
echo "Installing onyx executable"
+sudo mkdir -p "$BIN_DIR"
sudo cp ./bin/onyx "$BIN_DIR/onyx"
C_FILES="onyxrun wasm_runtime"
b32 bh_file_exists(char const* filename);
char* bh_path_get_full_name(char const* filename, bh_allocator a);
char* bh_path_get_parent(char const* filename, bh_allocator a);
+char* bh_path_convert_separators(char* path);
// This function returns a volatile pointer. Do not store it without copying!
// `included_folders` is bh_arr(const char *).
return fn;
}
+//
+// Modifies the path in-place.
+char* bh_path_convert_separators(char* path) {
+#if defined(_BH_LINUX)
+ #define DIR_SEPARATOR '/'
+ #define OTHER_SEPARATOR '\\'
+#elif defined(_BH_WINDOWS)
+ #define DIR_SEPARATOR '\\'
+ #define OTHER_SEPARATOR '/'
+#endif
+
+ fori (i, 0, (i64) strlen(path)) {
+ if (path[i] == OTHER_SEPARATOR) {
+ path[i] = DIR_SEPARATOR;
+ }
+ }
+
+ return path;
+}
+
bh_dir bh_dir_open(char* path) {
#ifdef _BH_WINDOWS
// This does not take into account #load_path'd folders...
+ bh_path_convert_separators(folder);
bh_dir dir = bh_dir_open(folder);
if (dir == NULL) {
onyx_report_error(include->token->pos, Error_Critical, "Could not find folder '%s'.", folder);
while (bh_dir_read(dir, &entry)) {
if (entry.type == BH_DIRENT_FILE && bh_str_ends_with(entry.name, ".onyx")) {
bh_snprintf(fullpath, 511, "%s/%s", folder, entry.name);
+ bh_path_convert_separators(fullpath);
u8* formatted_name = bh_path_get_full_name(fullpath, global_heap_allocator);
success = process_source_file(formatted_name, include->token->pos);
if (!success) break;
char *lib_path = malloc(lib_path_length);
strncpy(lib_path, wasm_bytes.data + cursor, lib_path_length);
lib_path[lib_path_length] = '\0';
+ bh_path_convert_separators(lib_path);
cursor += lib_path_length;
bh_arr_push(library_paths, lib_path);