Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for signing binaries #219

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 41 additions & 1 deletion src/main/java/edu/wpi/first/nativeutils/WPINativeUtils.java
Original file line number Diff line number Diff line change
@@ -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<Project> {
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);
Expand All @@ -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);
}
}
});
}
}
}
}
Loading