Skip to content

Commit

Permalink
Make Jaunch actually support the os-arch suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrueden committed Feb 2, 2024
1 parent 693a52c commit 265e2aa
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ The build process will:
* Three TOML configuration files, `jaunch.toml`, `jy.toml`, and `parsy.toml`;
* The `Props.class` helper program.

Then try running `app/jy` or `app/parsy` and watch the fireworks. If it doesn't
work, try `app/parsy --debug`, which will show what's happening under the hood.
Then run the `jy` or `parsy` binary in the `app` folder and watch the fireworks.
If it doesn't work, try appending the `--debug` flag, which will show what's
happening under the hood.

Note that these `jy` and `parsy` launchers are binary identical—each is
merely an illustration of how your native launcher could be named and work.
Expand Down
16 changes: 16 additions & 0 deletions src/c/jaunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
#include "posix.h"
#endif

#ifdef __x86_64__
#define OS_ARCH "x64"
#endif

#ifdef __aarch64__
#define OS_ARCH "aarch64"
#endif

// List of places to search for the jaunch configurator executable.
//
// NB: This list should align with the configDirs list in Jaunch.kt,
Expand Down Expand Up @@ -189,8 +197,16 @@ int main(const int argc, const char *argv[]) {
char *command = NULL;
size_t search_path_count = sizeof(JAUNCH_SEARCH_PATHS) / sizeof(char *);
for (size_t i = 0; i < search_path_count; i++) {
// First, look for jaunch configurator with a `-<os>-<arch>` suffix.
command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], JAUNCH_EXE"-"OS_NAME"-"OS_ARCH);
if (file_exists(command)) break;

// If not found, look for plain jaunch configurator with no suffix.
free(command);
command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], JAUNCH_EXE);
if (file_exists(command)) break;

// Nothing at this search path; clean up and move on to the next one.
free(command);
command = NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions src/c/linux.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <string.h>

#define OS_NAME "linux"

int isCommandAvailable(const char *command) {
return access(command, X_OK) == 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/c/macos.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <objc/objc.h>
#include <objc/NSObjCRuntime.h>

#define OS_NAME "macos"

void show_alert(const char *title, const char *message) {
/* TODO: Get this objc code working.
// Create an NSString from the C string
Expand Down
3 changes: 1 addition & 2 deletions src/c/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#include "common.h"

#define SLASH "/"

const char* JAUNCH_EXE = "jaunch";
#define JAUNCH_EXE "jaunch"

int file_exists(const char *path) {
return access(path, F_OK) == 0;
Expand Down
4 changes: 2 additions & 2 deletions src/c/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include "common.h"

#define OS_NAME "windows"
#define SLASH "\\"

const char* JAUNCH_EXE = "jaunch.exe";
#define JAUNCH_EXE "jaunch.exe"

void dlclose(void* library) { FreeLibrary(library); }
char* dlerror() { return "error" /*TODO: GetLastError()*/; }
Expand Down
12 changes: 10 additions & 2 deletions src/commonMain/kotlin/Jaunch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ fun main(args: Array<String>) {

// Load the configuration from the TOML file(s).
var config = readConfig(configDir / "jaunch.toml")
config += readConfig(configDir / "jaunch-$$OS_NAME.toml")
config += readConfig(configDir / "jaunch-$$OS_NAME-$CPU_ARCH.toml")
if (exeFile != null) {
// Parse and merge the app-specific TOML file as well.
config += readConfig(configDir / "${exeFile.base.name}.toml")
// Parse and merge the app-specific TOML file(s) as well.
var fileName = exeFile.base.name
while (true) {
config += readConfig(configDir / "$fileName.toml")
val dash = fileName.lastIndexOf("-")
if (dash < 0) break
fileName = fileName.substring(0, dash)
}
}

val programName = config.programName ?: exeFile?.base?.name ?: "Jaunch"
Expand Down

0 comments on commit 265e2aa

Please sign in to comment.