Skip to content

Commit

Permalink
Only add extra ldflags on linux (#901)
Browse files Browse the repository at this point in the history
Motivation:

We need to ensure we only add the extra ldflags on linux as otherwise
compilation will fail on macOS

Modifications:

Add the ldflags on linux only

Result:

Be able to compile on macOS again
  • Loading branch information
normanmaurer authored Oct 31, 2024
1 parent 6e5bf3f commit cfb021f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
31 changes: 29 additions & 2 deletions boringssl-static/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<msvcSslLibs>ssl.lib;crypto.lib</msvcSslLibs>
<cflags>-Werror -fno-omit-frame-pointer -fvisibility=hidden -Wunused -Wno-unused-value -O3</cflags>
<cppflags>-DHAVE_OPENSSL -I${boringsslSourceDir}/include</cppflags>
<ldflags>-L${boringsslHome}/ssl -L${boringsslHome}/crypto -lssl -lcrypto -static-libstdc++ -l:libstdc++.a</ldflags>
<ldflags>-L${boringsslHome}/ssl -L${boringsslHome}/crypto -lssl -lcrypto</ldflags>
<skipJapicmp>true</skipJapicmp>
<!-- We need to use the same module name for all our "native" impls as only one should be loaded -->
<javaModuleName>${javaDefaultModuleName}</javaModuleName>
Expand Down Expand Up @@ -563,6 +563,33 @@
</configuration>
</execution>

<execution>
<id>ldflags-setup</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<exportAntProperties>true</exportAntProperties>
<target>
<!-- Add the ant tasks from ant-contrib -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<echo message="Setup flags to use during linking" />

<!-- If we compile on linux we need to adjust the ldflags to correct link libstdc++ -->
<if>
<equals arg1="${os.detected.name}" arg2="linux" />
<then>
<property name="hawtjniLdflags" value="-L${boringsslHome}/ssl -L${boringsslHome}/crypto -lssl -lcrypto -static-libstdc++ -l:libstdc++.a" />
</then>
<else>
<property name="hawtjniLdflags" value="${ldflags}" />
</else>
</if>
</target>
</configuration>
</execution>

<!-- Build the additional JAR that contains the native library. -->
<execution>
<id>native-jar</id>
Expand Down Expand Up @@ -658,7 +685,7 @@
<configureArg>${macOsxDeploymentTarget}</configureArg>
<configureArg>CFLAGS=${cflags}</configureArg>
<configureArg>CPPFLAGS=${cppflags}</configureArg>
<configureArg>LDFLAGS=${ldflags}</configureArg>
<configureArg>LDFLAGS=${hawtjniLdflags}</configureArg>
</configureArgs>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public class NativeTest {
@Test
public void loadNativeLib() throws Exception {
String testClassesRoot = NativeTest.class.getProtectionDomain().getCodeSource().getLocation().getFile();
File f = new File(testClassesRoot + File.separator + "META-INF" + File.separator + "native");
File[] directories = new File(testClassesRoot + File.separator + "META-INF" + File.separator + "native")
.listFiles();
if (directories == null || directories.length != 1) {
throw new IllegalStateException("Could not find platform specific native directory");
throw new IllegalStateException("Could not find platform specific native directory: " + f);
}
String libName = System.mapLibraryName("netty_tcnative")
// Fix the filename (this is needed for macOS).
Expand Down

0 comments on commit cfb021f

Please sign in to comment.