Skip to content

Commit

Permalink
Specify the platform version and deployment target on macos (#11906)
Browse files Browse the repository at this point in the history
Motivation:

We should specify the platform version and deployment target when on macos as otherwise we might change requirements of minimal macOS version without notice it.

Modifications:

- Add -platform_version to the linker args
- Always specify MACOSX_DEPLOYMENT_TARGET target

Result:

Be able to use native macOS libs again on older macOS releases
  • Loading branch information
normanmaurer committed Dec 10, 2021
1 parent 4312720 commit 4ebeb74
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions resolver-dns-native-macos/pom.xml
Expand Up @@ -35,7 +35,7 @@
</os>
</activation>
<properties>
<jni.compiler.args.ldflags>LDFLAGS=-Wl,-weak_library,${unix.common.lib.unpacked.dir}/lib${unix.common.lib.name}.a</jni.compiler.args.ldflags>
<jni.compiler.args.ldflags>LDFLAGS=-Wl,-weak_library,${unix.common.lib.unpacked.dir}/lib${unix.common.lib.name}.a -Wl,-platform_version,macos,10.6,10.6</jni.compiler.args.ldflags>
<skipTests>false</skipTests>
</properties>
<build>
Expand Down Expand Up @@ -80,6 +80,7 @@
<configureArgs>
<arg>${jni.compiler.args.ldflags}</arg>
<arg>${jni.compiler.args.cflags}</arg>
<arg>MACOSX_DEPLOYMENT_TARGET=10.6</arg>
</configureArgs>
</configuration>
<goals>
Expand Down Expand Up @@ -135,7 +136,7 @@
<profile>
<id>mac-m1-cross-compile</id>
<properties>
<jni.compiler.args.ldflags>LDFLAGS=-arch arm64 -Wl,-weak_library,${unix.common.lib.unpacked.dir}/lib${unix.common.lib.name}.a</jni.compiler.args.ldflags>
<jni.compiler.args.ldflags>LDFLAGS=-arch arm64 -Wl,-weak_library,${unix.common.lib.unpacked.dir}/lib${unix.common.lib.name}.a -Wl,-platform_version,macos,11.0,11.0</jni.compiler.args.ldflags>
<jni.compiler.args.cflags>CFLAGS=-target arm64-apple-macos11 -O3 -Werror -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden -I${unix.common.include.unpacked.dir}</jni.compiler.args.cflags>

<!-- use aarch_64 as this is also what os.detected.arch will use on an aarch64 system -->
Expand Down Expand Up @@ -185,6 +186,7 @@
<arg>${jni.compiler.args.ldflags}</arg>
<arg>${jni.compiler.args.cflags}</arg>
<configureArg>--host=aarch64-apple-darwin</configureArg>
<arg>MACOSX_DEPLOYMENT_TARGET=11.0</arg>
</configureArgs>
</configuration>
<goals>
Expand Down
5 changes: 3 additions & 2 deletions transport-native-kqueue/pom.xml
Expand Up @@ -35,7 +35,7 @@
</os>
</activation>
<properties>
<jni.compiler.args.ldflags>LDFLAGS=-Wl,-weak_library,${unix.common.lib.unpacked.dir}/lib${unix.common.lib.name}.a</jni.compiler.args.ldflags>
<jni.compiler.args.ldflags>LDFLAGS=-Wl,-weak_library,${unix.common.lib.unpacked.dir}/lib${unix.common.lib.name}.a -Wl,-platform_version,macos,10.6,10.6</jni.compiler.args.ldflags>
<skipTests>false</skipTests>
</properties>
<build>
Expand Down Expand Up @@ -143,7 +143,7 @@
<!-- use aarch_64 as this is also what os.detected.arch will use on an aarch64 system -->
<jni.classifier>${os.detected.name}-aarch_64</jni.classifier>
<jni.compiler.args.cflags>CFLAGS=-target arm64-apple-macos11 -O3 -Werror -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden -I${unix.common.include.unpacked.dir}</jni.compiler.args.cflags>
<jni.compiler.args.ldflags>LDFLAGS=-arch arm64 -Wl,-weak_library,${unix.common.lib.unpacked.dir}/lib${unix.common.lib.name}.a</jni.compiler.args.ldflags>
<jni.compiler.args.ldflags>LDFLAGS=-arch arm64 -Wl,-weak_library,${unix.common.lib.unpacked.dir}/lib${unix.common.lib.name}.a -Wl,-platform_version,macos,11.0,11.0</jni.compiler.args.ldflags>
<skipTests>true</skipTests>
</properties>
<build>
Expand Down Expand Up @@ -188,6 +188,7 @@
<configureArgs>
<arg>${jni.compiler.args.ldflags}</arg>
<arg>${jni.compiler.args.cflags}</arg>
<arg>MACOSX_DEPLOYMENT_TARGET=11.0</arg>
<configureArg>--host=aarch64-apple-darwin</configureArg>
<configureArg>--libdir=${project.build.directory}/native-build/target/lib</configureArg>
</configureArgs>
Expand Down
5 changes: 3 additions & 2 deletions transport-native-unix-common/pom.xml
Expand Up @@ -154,7 +154,7 @@
<env key="OBJ_DIR" value="${nativeObjsOnlyDir}" />
<env key="JNI_PLATFORM" value="${jni.platform}" />
<env key="CFLAGS" value="-O3 -Werror -Wno-attributes -fPIC -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden" />
<env key="LDFLAGS" value="-Wl,--no-as-needed -lrt" />
<env key="LDFLAGS" value="-Wl,--no-as-needed -lrt -Wl,-platform_version,macos,10.2,10.2" />
<env key="LIB_NAME" value="${nativeLibName}" />
<!-- support for __attribute__((weak_import)) by the linker was added in 10.2 so ensure we
explicitly set the target platform. Otherwise we may get fatal link errors due to weakly linked
Expand Down Expand Up @@ -227,8 +227,9 @@
<env key="OBJ_DIR" value="${nativeObjsOnlyDir}" />
<env key="JNI_PLATFORM" value="${jni.platform}" />
<env key="CFLAGS" value="-target arm64-apple-macos11 -O3 -Werror -Wno-attributes -fPIC -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden" />
<env key="LDFLAGS" value="-arch arm64 -Wl,--no-as-needed -lrt" />
<env key="LDFLAGS" value="-arch arm64 -Wl,--no-as-needed -lrt -Wl,-platform_version,macos,11.0,11.0" />
<env key="LIB_NAME" value="${nativeLibName}" />
<env key="MACOSX_DEPLOYMENT_TARGET" value="11.0" />
</exec>
</target>
</configuration>
Expand Down

0 comments on commit 4ebeb74

Please sign in to comment.