Skip to content

Commit

Permalink
- clean up handling of version specific static java libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
kkriske committed Nov 16, 2023
1 parent ad6a116 commit 63c32fd
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,20 @@ public abstract class AbstractTargetConfiguration implements TargetConfiguration
protected final boolean crossCompile;

private final List<String> defaultAdditionalSourceFiles = Collections.singletonList("launcher.c");
private final List<String> defaultStaticJavaLibs = List.of("java", "nio", "zip", "net", "prefs", "jvm",
"fdlibm", "z", "dl", "j2pkcs11", "sunec", "jaas", "extnet");

/**
* Static Java libs required for all JDK major versions
*/
private final List<String> defaultStaticJavaLibsBase = List.of("java", "nio", "zip", "net", "prefs", "jvm",
"z", "dl", "j2pkcs11", "jaas", "extnet");
/**
* Static Java libs required for JDK major == 11
*/
private final List<String> defaultStaticJavaLibs11 = List.of("sunec");
/**
* Static Java libs required for JDK major < 21
*/
private final List<String> defaultStaticJavaLibs20 = List.of("fdlibm");

AbstractTargetConfiguration(ProcessPaths paths, InternalProjectConfiguration configuration) {
this.projectConfiguration = configuration;
Expand Down Expand Up @@ -926,7 +938,15 @@ String getAppPath(String appName) {
* linker when creating images for the specific target.
*/
List<String> getStaticJavaLibs() {
return defaultStaticJavaLibs;
int major = projectConfiguration.getJavaVersion().getMajor();
List<String> libs = new ArrayList<>(defaultStaticJavaLibsBase);
if (major == 11) {
libs.addAll(defaultStaticJavaLibs11);
}
if (major < 21) {
libs.addAll(defaultStaticJavaLibs20);
}
return libs;
}

/**
Expand All @@ -950,7 +970,6 @@ List<String> getOtherStaticLibs() {
*/
private List<String> getTargetSpecificJavaLinkLibraries() {
return Stream.concat(getStaticJavaLibs().stream(), getOtherStaticLibs().stream())
.filter(lib -> projectConfiguration.usesJDK11() || !lib.contains("sunec"))
.map(this::getLinkLibraryOption)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,20 @@ public class LinuxTargetConfiguration extends PosixTargetConfiguration {

private static final List<String> linuxLibs = Arrays.asList("z", "dl", "stdc++", "pthread");

private static final List<String> staticJavaLibs = Arrays.asList(
"java", "nio", "zip", "net", "prefs", "j2pkcs11", "sunec", "extnet", "fdlibm",
"fontmanager", "javajpeg", "lcms", "awt_headless", "awt"
);
/**
* fdlibm no longer required, unsure since when
* Static Java libs required for all JDK major versions
*/
private static final List<String> staticJavaLibs21 = Arrays.asList(
"java", "nio", "zip", "net", "prefs", "j2pkcs11", "sunec", "extnet",
"fontmanager", "javajpeg", "lcms", "awt_headless", "awt"
);
private static final List<String> staticJavaLibsBase = List.of(
"java", "nio", "zip", "net", "prefs", "j2pkcs11", "extnet",
"fontmanager", "javajpeg", "lcms", "awt_headless", "awt");
/**
* Static Java libs required for JDK major == 11
*/
private static final List<String> staticJavaLibs11 = List.of("sunec");
/**
* Static Java libs required for JDK major < 21
*/
private static final List<String> staticJavaLibs20 = List.of("fdlibm");

private static final List<String> staticJvmLibs = Arrays.asList(
"jvm", "libchelper"
Expand Down Expand Up @@ -242,11 +245,14 @@ List<String> getStaticJavaLibs() {
} catch (IOException ex) {
throw new RuntimeException ("No static java libs found, cannot continue");
}
List<String> libs;
if (projectConfiguration.getJavaVersion().getMajor() >= 21) {
libs = staticJavaLibs21;
} else {
libs = staticJavaLibs;

int major = projectConfiguration.getJavaVersion().getMajor();
List<String> libs = new ArrayList<>(staticJavaLibsBase);
if (major == 11) {
libs.addAll(staticJavaLibs11);
}
if (major < 21) {
libs.addAll(staticJavaLibs20);
}
return libs.stream()
.map(lib -> javaStaticLibPath.resolve("lib" + lib + ".a").toString())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022, Gluon
* Copyright (c) 2019, 2023, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -56,9 +56,21 @@ public class MacOSTargetConfiguration extends DarwinTargetConfiguration {
"ApplicationServices", "OpenGL", "QuartzCore", "Security", "Accelerate"
);

private static final List<String> staticJavaLibs = Arrays.asList(
"java", "nio", "zip", "net", "prefs", "j2pkcs11", "fdlibm", "sunec", "extnet"
/**
* Static Java libs required for all JDK major versions
*/
private static final List<String> staticJavaLibsBase = Arrays.asList(
"java", "nio", "zip", "net", "prefs", "j2pkcs11", "extnet"
);
/**
* Static Java libs required for JDK major == 11
*/
private static final List<String> staticJavaLibs11 = List.of("sunec");
/**
* Static Java libs required for JDK major < 21
*/
private static final List<String> staticJavaLibs20 = List.of("fdlibm");

private static final List<String> staticJvmLibs = Arrays.asList(
"jvm", "libchelper", "darwin"
);
Expand All @@ -72,7 +84,7 @@ public class MacOSTargetConfiguration extends DarwinTargetConfiguration {
"WTF", "icuuc", "icudata"
);

public MacOSTargetConfiguration(ProcessPaths paths, InternalProjectConfiguration configuration ) {
public MacOSTargetConfiguration(ProcessPaths paths, InternalProjectConfiguration configuration) {
super(paths, configuration);
}

Expand Down Expand Up @@ -142,7 +154,15 @@ List<String> getTargetSpecificLinkFlags(boolean useJavaFX, boolean usePrismSW) {

@Override
List<String> getStaticJavaLibs() {
return staticJavaLibs;
int major = projectConfiguration.getJavaVersion().getMajor();
List<String> libs = new ArrayList<>(staticJavaLibsBase);
if (major == 11) {
libs.addAll(staticJavaLibs11);
}
if (major < 21) {
libs.addAll(staticJavaLibs20);
}
return libs;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,33 @@

public class WindowsTargetConfiguration extends AbstractTargetConfiguration {

private static final List<String> javaWindowsLibs = Arrays.asList(
/**
* Static Windows libs required for all JDK major versions
*/
private static final List<String> javaWindowsLibsBase = List.of(
"advapi32", "iphlpapi", "secur32", "userenv", "version", "ws2_32", "winhttp", "ncrypt", "crypt32");
/**
* mswsock required as of jdk 20
* Static Windows libs required for JDK major >= 20
*/
private static final List<String> javaWindowsLibsJdk20 = Arrays.asList(
"advapi32", "iphlpapi", "secur32", "userenv", "version", "ws2_32", "winhttp", "ncrypt", "crypt32", "mswsock");
private static final List<String> javaWindowsLibs20 = List.of("mswsock");

private static final List<String> staticJavaLibs = Arrays.asList(
"j2pkcs11", "java", "net", "nio", "prefs", "fdlibm", "sunec", "zip", "sunmscapi");
/**
* extnet required since jdk 19
* fdlibm no longer required, unsure since when
* Static Java libs required for all JDK major versions
*/
private static final List<String> staticJavaLibsBase = List.of(
"j2pkcs11", "java", "net", "nio", "prefs", "zip", "sunmscapi");
/**
* Static Java libs required for JDK major == 11
*/
private static final List<String> staticJavaLibs11 = List.of("sunec");
/**
* Static Java libs required for JDK major < 21
*/
private static final List<String> staticJavaLibs21 = Arrays.asList(
"j2pkcs11", "java", "net", "nio", "prefs", "sunec", "extnet", "zip", "sunmscapi");
private static final List<String> staticJavaLibs20 = List.of("fdlibm");
/**
* Static Java libs required for JDK major >= 21
*/
private static final List<String> staticJavaLibs21 = List.of("extnet");

private static final List<String> staticJvmLibs = Arrays.asList(
"jvm", "libchelper");
Expand Down Expand Up @@ -150,19 +161,27 @@ String getLinkOutputName() {

@Override
List<String> getStaticJavaLibs() {
if (projectConfiguration.getJavaVersion().getMajor() >= 21) {
return staticJavaLibs21;
int major = projectConfiguration.getJavaVersion().getMajor();
List<String> libs = new ArrayList<>(staticJavaLibsBase);
if (major == 11) {
libs.addAll(staticJavaLibs11);
}
if (major < 21) {
libs.addAll(staticJavaLibs20);
}
return staticJavaLibs;
if (major >= 21) {
libs.addAll(staticJavaLibs21);
}
return libs;
}

@Override
List<String> getOtherStaticLibs() {
int major = projectConfiguration.getJavaVersion().getMajor();
List<String> libs = new ArrayList<>(staticJvmLibs);
if (projectConfiguration.getJavaVersion().getMajor() >= 20) {
libs.addAll(javaWindowsLibsJdk20);
} else {
libs.addAll(javaWindowsLibs);
libs.addAll(javaWindowsLibsBase);
if (major >= 20) {
libs.addAll(javaWindowsLibs20);
}
return libs;
}
Expand Down

0 comments on commit 63c32fd

Please sign in to comment.