Skip to content

Commit 265e2aa

Browse files
committed
Make Jaunch actually support the os-arch suffix
1 parent 693a52c commit 265e2aa

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ The build process will:
3838
* Three TOML configuration files, `jaunch.toml`, `jy.toml`, and `parsy.toml`;
3939
* The `Props.class` helper program.
4040

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

4445
Note that these `jy` and `parsy` launchers are binary identical—each is
4546
merely an illustration of how your native launcher could be named and work.

src/c/jaunch.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
#include "posix.h"
4545
#endif
4646

47+
#ifdef __x86_64__
48+
#define OS_ARCH "x64"
49+
#endif
50+
51+
#ifdef __aarch64__
52+
#define OS_ARCH "aarch64"
53+
#endif
54+
4755
// List of places to search for the jaunch configurator executable.
4856
//
4957
// NB: This list should align with the configDirs list in Jaunch.kt,
@@ -189,8 +197,16 @@ int main(const int argc, const char *argv[]) {
189197
char *command = NULL;
190198
size_t search_path_count = sizeof(JAUNCH_SEARCH_PATHS) / sizeof(char *);
191199
for (size_t i = 0; i < search_path_count; i++) {
200+
// First, look for jaunch configurator with a `-<os>-<arch>` suffix.
201+
command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], JAUNCH_EXE"-"OS_NAME"-"OS_ARCH);
202+
if (file_exists(command)) break;
203+
204+
// If not found, look for plain jaunch configurator with no suffix.
205+
free(command);
192206
command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], JAUNCH_EXE);
193207
if (file_exists(command)) break;
208+
209+
// Nothing at this search path; clean up and move on to the next one.
194210
free(command);
195211
command = NULL;
196212
}

src/c/linux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <string.h>
22

3+
#define OS_NAME "linux"
4+
35
int isCommandAvailable(const char *command) {
46
return access(command, X_OK) == 0;
57
}

src/c/macos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <objc/objc.h>
22
#include <objc/NSObjCRuntime.h>
33

4+
#define OS_NAME "macos"
5+
46
void show_alert(const char *title, const char *message) {
57
/* TODO: Get this objc code working.
68
// Create an NSString from the C string

src/c/posix.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include "common.h"
55

66
#define SLASH "/"
7-
8-
const char* JAUNCH_EXE = "jaunch";
7+
#define JAUNCH_EXE "jaunch"
98

109
int file_exists(const char *path) {
1110
return access(path, F_OK) == 0;

src/c/win32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "common.h"
44

5+
#define OS_NAME "windows"
56
#define SLASH "\\"
6-
7-
const char* JAUNCH_EXE = "jaunch.exe";
7+
#define JAUNCH_EXE "jaunch.exe"
88

99
void dlclose(void* library) { FreeLibrary(library); }
1010
char* dlerror() { return "error" /*TODO: GetLastError()*/; }

src/commonMain/kotlin/Jaunch.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,17 @@ fun main(args: Array<String>) {
7676

7777
// Load the configuration from the TOML file(s).
7878
var config = readConfig(configDir / "jaunch.toml")
79+
config += readConfig(configDir / "jaunch-$$OS_NAME.toml")
80+
config += readConfig(configDir / "jaunch-$$OS_NAME-$CPU_ARCH.toml")
7981
if (exeFile != null) {
80-
// Parse and merge the app-specific TOML file as well.
81-
config += readConfig(configDir / "${exeFile.base.name}.toml")
82+
// Parse and merge the app-specific TOML file(s) as well.
83+
var fileName = exeFile.base.name
84+
while (true) {
85+
config += readConfig(configDir / "$fileName.toml")
86+
val dash = fileName.lastIndexOf("-")
87+
if (dash < 0) break
88+
fileName = fileName.substring(0, dash)
89+
}
8290
}
8391

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

0 commit comments

Comments
 (0)