Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/gluonhq/substrate/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,9 @@ public enum Profile {
*/
public static final String NATIVE_IMAGE_ARG_CLASSPATH = "-cp";

/**
* Linker flags
*/
public static final String WL_WHOLE_ARCHIVE = "-Wl,--whole-archive";
public static final String WL_NO_WHOLE_ARCHIVE = "-Wl,--no-whole-archive";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Gluon
* Copyright (c) 2019, 2021, 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 @@ -96,7 +96,7 @@ public abstract class AbstractTargetConfiguration implements TargetConfiguration
final ProcessPaths paths;
protected final boolean crossCompile;

private List<String> defaultAdditionalSourceFiles = Collections.singletonList("launcher.c");
private final List<String> defaultAdditionalSourceFiles = Collections.singletonList("launcher.c");

AbstractTargetConfiguration(ProcessPaths paths, InternalProjectConfiguration configuration) {
this.projectConfiguration = configuration;
Expand Down Expand Up @@ -203,14 +203,17 @@ public boolean link() throws IOException, InterruptedException {
.map(sourceFile -> gvmAppPath.resolve(sourceFile).toString())
.collect(Collectors.toList()));

linkRunner.addArgs(getTargetSpecificJavaLinkLibraries());
linkRunner.addArgs(getTargetSpecificLinkFlags(projectConfiguration.isUseJavaFX(),
List<String> linkFlags = new ArrayList<>(getTargetSpecificJavaLinkLibraries());
linkFlags.addAll(getTargetSpecificLinkFlags(projectConfiguration.isUseJavaFX(),
projectConfiguration.isUsePrismSW()));

linkRunner.addArgs(getTargetSpecificLinkOutputFlags());
linkFlags.addAll(getTargetSpecificLinkOutputFlags());

linkRunner.addArgs(getLinkerLibraryPathFlags());
linkRunner.addArgs(getNativeLibsLinkFlags());
linkFlags.addAll(getLinkerLibraryPathFlags());
linkFlags.addAll(getNativeLibsLinkFlags());

linkRunner.addArgs(Strings.removeDuplicates(linkFlags,
List.of(Constants.WL_WHOLE_ARCHIVE, Constants.WL_NO_WHOLE_ARCHIVE)));
linkRunner.setInfo(true);
linkRunner.setLogToFile(true);
int result = linkRunner.runProcess("link");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import static com.gluonhq.substrate.Constants.ANDROID_PROJECT_NAME;
import static com.gluonhq.substrate.Constants.DALVIK_PRECOMPILED_CLASSES;
import static com.gluonhq.substrate.Constants.META_INF_SUBSTRATE_DALVIK;
import static com.gluonhq.substrate.Constants.WL_NO_WHOLE_ARCHIVE;
import static com.gluonhq.substrate.Constants.WL_WHOLE_ARCHIVE;
import static com.gluonhq.substrate.model.ReleaseConfiguration.DEFAULT_CODE_NAME;
import static com.gluonhq.substrate.model.ReleaseConfiguration.DEFAULT_CODE_VERSION;

Expand All @@ -69,8 +71,6 @@ public class AndroidTargetConfiguration extends PosixTargetConfiguration {
private static final String ANDROID_TRIPLET = new Triplet(Constants.Profile.ANDROID).toString();
private static final String ANDROID_MIN_SDK_VERSION = "21";
private static final List<String> ANDROID_KEYSTORE_EXTENSIONS = List.of(".keystore", ".jks");
private static final String WL_WHOLE_ARCHIVE = "-Wl,--whole-archive";
private static final String WL_NO_WHOLE_ARCHIVE = "-Wl,--no-whole-archive";

private final String ndk;
private final String sdk;
Expand Down Expand Up @@ -265,10 +265,9 @@ List<String> getTargetSpecificCCompileFlags() {
@Override
List<String> getTargetSpecificLinkFlags(boolean useJavaFX, boolean usePrismSW) {
if (!useJavaFX) return linkFlags;
List<String> answer = new ArrayList<>();
answer.addAll(linkFlags);
List<String> answer = new ArrayList<>(linkFlags);
if (projectConfiguration.hasWeb()) {
javafxLinkFlags.addAll(Arrays.asList(WL_WHOLE_ARCHIVE, javafxWebLib, WL_NO_WHOLE_ARCHIVE));
javafxLinkFlags.add(javafxLinkFlags.indexOf(WL_NO_WHOLE_ARCHIVE) - 1, javafxWebLib);
}
answer.addAll(javafxLinkFlags);
return answer;
Expand All @@ -288,11 +287,11 @@ protected List<Path> getStaticJDKLibPaths() throws IOException {
@Override
List<String> getTargetSpecificNativeLibsFlags(Path libPath, List<String> libs) {
List<String> linkFlags = new ArrayList<>();
linkFlags.add("-Wl,--whole-archive");
linkFlags.add(WL_WHOLE_ARCHIVE);
linkFlags.addAll(libs.stream()
.map(s -> libPath.resolve(s).toString())
.collect(Collectors.toList()));
linkFlags.add("-Wl,--no-whole-archive");
linkFlags.add(WL_NO_WHOLE_ARCHIVE);
return linkFlags;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Gluon
* Copyright (c) 2019, 2021, 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 @@ -50,6 +50,9 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static com.gluonhq.substrate.Constants.WL_NO_WHOLE_ARCHIVE;
import static com.gluonhq.substrate.Constants.WL_WHOLE_ARCHIVE;

public class LinuxTargetConfiguration extends PosixTargetConfiguration {

private static final Version COMPILER_MINIMAL_VERSION = new Version(6);
Expand All @@ -67,43 +70,41 @@ public class LinuxTargetConfiguration extends PosixTargetConfiguration {
);

private static final List<String> linuxfxlibs = List.of(
"-Wl,--whole-archive",
WL_WHOLE_ARCHIVE,
"-lprism_es2", "-lglass", "-lglassgtk3", "-ljavafx_font",
"-ljavafx_font_freetype", "-ljavafx_font_pango", "-ljavafx_iio",
"-Wl,--no-whole-archive"
WL_NO_WHOLE_ARCHIVE
);

// we might rename libprism_es2_monocle.a to libprism_es2.a in the future
private static final List<String> linuxfxlibsaarch64 = List.of(
"-Wl,--whole-archive",
WL_WHOLE_ARCHIVE,
"-lprism_es2_monocle", "-lglass", "-lglassgtk3", "-lglass_monocle", "-ljavafx_font",
"-ljavafx_font_freetype", "-ljavafx_font_pango", "-ljavafx_iio", "-lgluon_drm",
"-Wl,--no-whole-archive"
WL_NO_WHOLE_ARCHIVE
);

private static final List<String> linuxfxMedialibs = List.of(
"-ljfxmedia", "-lfxplugins", "-lavplugin",
"-Wl,--no-whole-archive"
WL_NO_WHOLE_ARCHIVE
);
private static final List<String> linuxfxWeblibs = List.of(
"-ljfxwebkit",
"-Wl,--no-whole-archive",
WL_NO_WHOLE_ARCHIVE,
"-lWebCore", "-lXMLJava", "-lJavaScriptCore", "-lbmalloc",
"-licui18n", "-lSqliteJava", "-lXSLTJava", "-lPAL", "-lWebCoreTestSupport",
"-lWTF", "-licuuc", "-licudata"
);

private String[] capFiles = {"AArch64LibCHelperDirectives.cap",
private final String[] capFiles = {"AArch64LibCHelperDirectives.cap",
"AMD64LibCHelperDirectives.cap", "BuiltinDirectives.cap",
"JNIHeaderDirectives.cap", "LibFFIHeaderDirectives.cap",
"PosixDirectives.cap"};

private String llvmCapFile = "LLVMDirectives.cap";

private final String capLocation = "/native/linux-aarch64/cap/";

private static final List<String> linuxfxSWlibs = Arrays.asList(
"-Wl,--whole-archive", "-lprism_sw", "-Wl,--no-whole-archive");
"-lprism_sw", WL_NO_WHOLE_ARCHIVE);

private final String sysroot;

Expand Down Expand Up @@ -189,24 +190,25 @@ List<String> getTargetSpecificLinkFlags(boolean useJavaFX, boolean usePrismSW) t
answer.addAll(linuxfxlibs);
}
// TODO: Refactor
if (usePrismSW || crossCompile) {
answer.remove(WL_NO_WHOLE_ARCHIVE);
answer.addAll(linuxfxSWlibs);
}
if (projectConfiguration.getClasspath().contains("javafx-media")) {
// for now, we don't have media on AARCH64
if (!isAarch64) {
answer.remove(answer.size() - 1);
answer.remove(WL_NO_WHOLE_ARCHIVE);
answer.addAll(linuxfxMedialibs);
}
}
if (projectConfiguration.hasWeb()) {
answer.remove(answer.size() - 1);
answer.remove(WL_NO_WHOLE_ARCHIVE);
answer.addAll(linuxfxWeblibs);
}
if (!crossCompile) {
answer.addAll(LinuxLinkerFlags.getMediaLinkerFlags());
}
answer.addAll(LinuxLinkerFlags.getLinkerFlags());
if (usePrismSW || crossCompile) {
answer.addAll(linuxfxSWlibs);
}
if (isAarch64) {
answer.add("-lEGL");
answer.add("-ldrm");
Expand All @@ -221,11 +223,11 @@ List<String> getTargetSpecificLinkFlags(boolean useJavaFX, boolean usePrismSW) t
@Override
List<String> getTargetSpecificNativeLibsFlags(Path libPath, List<String> libs) {
List<String> linkFlags = new ArrayList<>();
linkFlags.add("-Wl,--whole-archive");
linkFlags.add(WL_WHOLE_ARCHIVE);
linkFlags.addAll(libs.stream()
.map(s -> libPath.resolve(s).toString())
.collect(Collectors.toList()));
linkFlags.add("-Wl,--no-whole-archive");
linkFlags.add(WL_NO_WHOLE_ARCHIVE);
return linkFlags;
}

Expand Down
48 changes: 47 additions & 1 deletion src/main/java/com/gluonhq/substrate/util/Strings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Gluon
* Copyright (c) 2019, 2021, 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 @@ -36,10 +36,14 @@
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public final class Strings {

private static final Pattern substitutionPattern = Pattern.compile("\\$\\{(.+?)}");
private static final String KEEP_STRING_SUFFIX = "_$$";

/**
* Replaces keys within the template with values using context function
* Throws IllegalArgumentException if the key found in the template has no corresponding value
Expand Down Expand Up @@ -108,4 +112,46 @@ public static String randomString(int targetStringLength) {
.toString();
}

/**
* Removes duplicated strings from a sourceList list, keeping the items with higher index
* in the list. Any item in the keep list will not be removed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is not guaranteed to be the correct approach. If an entry appear twice, there are a number of possible scenario's. Both may be needed, first may be needed, last may be needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a keep list for strings that might be duplicated and needed.
So far the case I found is the whole/no-whole combination.
I've tested this PR in all possible platforms, and there was no issue removing the rest of the duplicates.

*
* @param sourceList the initial list of strings with possible duplicates
* @param keepList the list of items that can't be removed
* @return
*/
public static List<String> removeDuplicates(List<String> sourceList, List<String> keepList) {
List<String> modSourceList = IntStream.range(0, sourceList.size())
.mapToObj(i -> {
String s = sourceList.get(i);
if (keepList.stream().anyMatch(k -> k.equals(s))) {
return s + KEEP_STRING_SUFFIX + i;
}
return s;
}).collect(Collectors.toList());

List<String> uniqueReversedSourceList = reverseIndices(0, modSourceList.size())
.mapToObj(modSourceList::get)
.distinct()
.collect(Collectors.toList());

List<String> uniqueSortedSourceList = reverseIndices(0, uniqueReversedSourceList.size())
.mapToObj(uniqueReversedSourceList::get)
.collect(Collectors.toList());

return uniqueSortedSourceList.stream()
.map(s -> s.contains(KEEP_STRING_SUFFIX) ? s.substring(0, s.indexOf(KEEP_STRING_SUFFIX)) : s)
.collect(Collectors.toList());
}

/**
* Returns an IntStream with reversed indices
* @param from initial index of a given range
* @param to final index of a given range
* @return an {@link IntStream}
*/
private static IntStream reverseIndices(int from, int to) {
return IntStream.range(from, to)
.map(i -> to - i + from - 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class LinuxLinkerFlags {
* name that provides it.
*/
private static final List<PkgInfo> LINK_DEPENDENCIES = List.of(
hardwired("-Wl,--no-whole-archive"),

activeOf(debian("gl", "libgl-dev"),
fedora("gl", "mesa-libGL-devel")),
activeOf(debian("x11", "libx11-dev"),
Expand Down