diff --git a/build.gradle b/build.gradle index 4d0ab0b..d154101 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ java { allprojects { group = "edu.wpi.first" - version = "2025.5.0" + version = "2025.6.0" if (project.hasProperty('publishVersion')) { version = project.publishVersion diff --git a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java index 6b03879..a3d5dea 100644 --- a/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java +++ b/src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java @@ -1,9 +1,25 @@ package edu.wpi.first.nativeutils; +import java.io.IOException; + import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.tasks.options.Option; +import org.gradle.nativeplatform.tasks.AbstractLinkTask; +import org.gradle.nativeplatform.tasks.LinkExecutable; public class WPINativeUtils implements Plugin { + private String developerID = null; + + @Option(option = "sign", description = "Sign with developer ID (MacOS only)") + public void sign(String developerID) { + if (!System.getProperty("os.name").startsWith("Mac")) { + throw new RuntimeException("Can't sign binaries on non mac platforms"); + } + + this.developerID = developerID; + } + @Override public void apply(Project project) { project.getPluginManager().apply(NativeUtils.class); @@ -13,5 +29,29 @@ public void apply(Project project) { nativeExt.addWpiExtension(); project.getPluginManager().apply(RpathRules.class); - } + + if (System.getProperty("os.name").startsWith("Mac")) { + if (developerID != null) { + project.getTasks().withType(AbstractLinkTask.class).forEach((task) -> { + // Don't sign any executables because codesign complains + // about relative rpath. + if (!(task instanceof LinkExecutable)) { + // Get path to binary. + String path = task.getLinkedFile().getAsFile().get().getAbsolutePath(); + ProcessBuilder builder = new ProcessBuilder(); + var codesigncommand = String.format("codesign --force --strict --timestamp --options=runtime " + + "--version -s %s %s", developerID, path); + builder.command("sh", "-c", codesigncommand); + builder.directory(project.getRootDir()); + + try { + builder.start(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + } + } + } }