-
Notifications
You must be signed in to change notification settings - Fork 615
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
Don't read protobuf static data across shared library lines directly #6979
Merged
Merged
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e3ee69f
Don't read protobuf static data across shared library lines directly
ThadHouse f092261
Add plugin to add new exports
ThadHouse d226abf
Update upstream utils for descriptor changes.
ThadHouse e6241cf
Include jar file in repo
ThadHouse e035380
Merge branch 'protobufstaticdata' of https://github.com/thadhouse/all…
ThadHouse 1b995bd
CMake
ThadHouse d11f8b0
Commit jar
ThadHouse e99e594
Configure proto to use java
ThadHouse 2865f98
Undo accidental change
ThadHouse fc8f477
Formatting fixes
github-actions[bot] ba47198
Fix jar to be Java 8
ThadHouse e03dc72
Merge branch 'protobufstaticdata' of https://github.com/thadhouse/all…
ThadHouse b2c3b9e
Rebuild jar
ThadHouse 14ff5b3
Fix java 8 again
ThadHouse c417dcc
Fix cmake
ThadHouse cd415c1
Update native-utils
ThadHouse 834fb29
Generate def file
ThadHouse 5700470
Another cmake fix
ThadHouse 5896ff0
One more fix
ThadHouse d001a37
A few more things
ThadHouse c3db9ec
More cmake
ThadHouse 07795a6
Formatting
ThadHouse 83432d5
Fix path
ThadHouse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,3 +252,6 @@ coverage_report/ | |
|
||
# ctest | ||
/Testing/ | ||
|
||
# protobuf | ||
!wpiprotoplugin.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
project(protoplugin) | ||
|
||
set(PROTO_JAR ${CMAKE_CURRENT_SOURCE_DIR}/binary/wpiprotoplugin.jar) | ||
|
||
configure_file( | ||
${CMAKE_CURRENT_SOURCE_DIR}/binary/wpiprotoplugin.sh.in | ||
${CMAKE_CURRENT_BINARY_DIR}/wpiprotoplugin.sh | ||
@ONLY | ||
) | ||
configure_file( | ||
${CMAKE_CURRENT_SOURCE_DIR}/binary/wpiprotoplugin.bat.in | ||
${CMAKE_CURRENT_BINARY_DIR}/wpiprotoplugin.bat | ||
@ONLY | ||
) | ||
|
||
if(WIN32) | ||
set(PROTOC_WPILIB_PLUGIN ${CMAKE_CURRENT_BINARY_DIR}/wpiprotoplugin.bat PARENT_SCOPE) | ||
else() | ||
set(PROTOC_WPILIB_PLUGIN ${CMAKE_CURRENT_BINARY_DIR}/wpiprotoplugin.sh PARENT_SCOPE) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@ECHO OFF | ||
"@Java_JAVA_EXECUTABLE@" -jar "@PROTO_JAR@" %* |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
exec "@Java_JAVA_EXECUTABLE@" -jar "@PROTO_JAR@" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
plugins { | ||
id 'application' | ||
id 'java' | ||
id 'com.gradleup.shadow' version '8.3.0' | ||
} | ||
|
||
application { | ||
mainClass = "org.wpilib.ProtoCDllGenerator" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation "com.google.protobuf:protobuf-java:3.21.12" | ||
} | ||
|
||
java { | ||
sourceCompatibility = 8 | ||
targetCompatibility = 8 | ||
} | ||
|
||
def cshadow = project.tasks.register("copyShadow", Copy) { | ||
from(tasks.shadowJar.archiveFile) { | ||
rename { | ||
"wpiprotoplugin.jar" | ||
} | ||
} | ||
into layout.projectDirectory.dir("binary") | ||
} | ||
|
||
build.dependsOn cshadow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
||
ThadHouse marked this conversation as resolved.
Show resolved
Hide resolved
|
76 changes: 76 additions & 0 deletions
76
protoplugin/src/main/java/org/wpilib/ProtoCDllGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package org.wpilib; | ||
|
||
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; | ||
import com.google.protobuf.Descriptors; | ||
import com.google.protobuf.Descriptors.Descriptor; | ||
import com.google.protobuf.Descriptors.DescriptorValidationException; | ||
import com.google.protobuf.Descriptors.FieldDescriptor; | ||
import com.google.protobuf.Descriptors.FieldDescriptor.Type; | ||
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; | ||
|
||
public final class ProtoCDllGenerator { | ||
private ProtoCDllGenerator() { | ||
} | ||
|
||
public static void main(String[] args) throws IOException, DescriptorValidationException { | ||
CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in); | ||
|
||
Map<String, Descriptors.FileDescriptor> descriptors = new HashMap<>(); | ||
|
||
Descriptors.FileDescriptor[] tmpArray = new Descriptors.FileDescriptor[0]; | ||
|
||
for (FileDescriptorProto proto : request.getProtoFileList()) { | ||
// Make array of file descriptors that exists | ||
Descriptors.FileDescriptor[] depArray = descriptors.values().toArray(tmpArray); | ||
Descriptors.FileDescriptor desc = Descriptors.FileDescriptor.buildFrom(proto, depArray); | ||
descriptors.put(proto.getName(), desc); | ||
} | ||
|
||
// Filter to generated descriptors | ||
CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder(); | ||
|
||
for (String genFile : request.getFileToGenerateList()) { | ||
Descriptors.FileDescriptor desc = descriptors.get(genFile); | ||
|
||
for (Descriptor msg : desc.getMessageTypes()) { | ||
for (FieldDescriptor field : msg.getFields()) { | ||
if (field.getType() == Type.MESSAGE && !field.isRepeated()) { | ||
// If we have a nested non repeated field, we need a custom accessor | ||
String type = field.getMessageType().getFullName(); | ||
type = "::" + type.replaceAll("\\.", "::"); | ||
|
||
// Add definition | ||
response.addFileBuilder() | ||
.setName(desc.getName().replace("proto", "pb.h")) | ||
.setInsertionPoint("class_scope:" + msg.getFullName()) | ||
.setContent("// Custom WPILib Accessor\n" | ||
+ "bool wpi_has_" + field.getName() + "() const;\n" | ||
+ "const " + type + "& wpi_" + field.getName() + "() const;\n"); | ||
|
||
// Add implementation. As were in the cc file for the proto | ||
// we can just call straight through to the inline definitions | ||
response.addFileBuilder() | ||
.setName(desc.getName().replace("proto", "pb.cc")) | ||
.setInsertionPoint("namespace_scope") | ||
.setContent("// Custom WPILib Accessor\n" | ||
+ "bool " + msg.getName() + "::wpi_has_" + field.getName() + "() const { return has_" | ||
+ field.getName() + "(); }\n" | ||
+ "const " + type + "& " + msg.getName() + "::wpi_" + field.getName() + "() const { return " | ||
+ field.getName() + "(); }\n"); | ||
} | ||
} | ||
} | ||
} | ||
response.build().writeTo(System.out); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0001-Fix-sign-compare-warnings.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Sat, 10 Jun 2023 14:13:07 -0700 | ||
Subject: [PATCH 01/12] Fix sign-compare warnings | ||
Subject: [PATCH 01/13] Fix sign-compare warnings | ||
|
||
--- | ||
src/google/protobuf/compiler/importer.cc | 2 +- | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0002-Remove-redundant-move.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Sat, 10 Jun 2023 14:41:39 -0700 | ||
Subject: [PATCH 02/12] Remove redundant move | ||
Subject: [PATCH 02/13] Remove redundant move | ||
|
||
--- | ||
src/google/protobuf/extension_set.h | 2 +- | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0003-Fix-maybe-uninitialized-warnings.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Sat, 10 Jun 2023 15:00:20 -0700 | ||
Subject: [PATCH 03/12] Fix maybe-uninitialized warnings | ||
Subject: [PATCH 03/13] Fix maybe-uninitialized warnings | ||
|
||
--- | ||
src/google/protobuf/arena.cc | 6 +++--- | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0004-Fix-coded_stream-WriteRaw.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Sat, 10 Jun 2023 15:03:38 -0700 | ||
Subject: [PATCH 04/12] Fix coded_stream WriteRaw | ||
Subject: [PATCH 04/13] Fix coded_stream WriteRaw | ||
|
||
--- | ||
src/google/protobuf/implicit_weak_message.h | 2 +- | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0005-Suppress-enum-enum-conversion-warning.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Sat, 10 Jun 2023 15:13:45 -0700 | ||
Subject: [PATCH 05/12] Suppress enum-enum conversion warning | ||
Subject: [PATCH 05/13] Suppress enum-enum conversion warning | ||
|
||
--- | ||
src/google/protobuf/generated_message_tctable_impl.h | 9 +++++++++ | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0006-Fix-noreturn-function-returning.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Sat, 10 Jun 2023 15:16:46 -0700 | ||
Subject: [PATCH 06/12] Fix noreturn function returning | ||
Subject: [PATCH 06/13] Fix noreturn function returning | ||
|
||
--- | ||
src/google/protobuf/generated_message_tctable_impl.h | 3 +++ | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Sat, 10 Jun 2023 15:59:45 -0700 | ||
Subject: [PATCH 07/12] Work around GCC 12 restrict warning compiler bug | ||
Subject: [PATCH 07/13] Work around GCC 12 restrict warning compiler bug | ||
|
||
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329 | ||
--- | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0008-Disable-MSVC-switch-warning.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Tue, 13 Jun 2023 23:56:15 -0700 | ||
Subject: [PATCH 08/12] Disable MSVC switch warning | ||
Subject: [PATCH 08/13] Disable MSVC switch warning | ||
|
||
--- | ||
src/google/protobuf/generated_message_reflection.cc | 4 ++++ | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0009-Disable-unused-function-warning.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Tue, 13 Jun 2023 23:58:50 -0700 | ||
Subject: [PATCH 09/12] Disable unused function warning | ||
Subject: [PATCH 09/13] Disable unused function warning | ||
|
||
--- | ||
src/google/protobuf/generated_message_tctable_lite.cc | 4 ++++ | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0010-Disable-pedantic-warning.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Wed, 14 Jun 2023 00:02:26 -0700 | ||
Subject: [PATCH 10/12] Disable pedantic warning | ||
Subject: [PATCH 10/13] Disable pedantic warning | ||
|
||
--- | ||
src/google/protobuf/descriptor.h | 8 ++++++++ | ||
|
2 changes: 1 addition & 1 deletion
2
upstream_utils/protobuf_patches/0011-Avoid-use-of-sprintf.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Peter Johnson <[email protected]> | ||
Date: Mon, 9 Oct 2023 19:28:08 -0700 | ||
Subject: [PATCH 11/12] Avoid use of sprintf | ||
Subject: [PATCH 11/13] Avoid use of sprintf | ||
|
||
--- | ||
src/google/protobuf/stubs/strutil.cc | 14 +++++++++++--- | ||
|
2 changes: 1 addition & 1 deletion
2
...ream_utils/protobuf_patches/0012-Suppress-stringop-overflow-warning-false-positives.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Tyler Veness <[email protected]> | ||
Date: Fri, 10 Nov 2023 14:17:53 -0800 | ||
Subject: [PATCH 12/12] Suppress stringop-overflow warning false positives | ||
Subject: [PATCH 12/13] Suppress stringop-overflow warning false positives | ||
|
||
--- | ||
src/google/protobuf/io/coded_stream.h | 7 +++++++ | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a CI check similar to pregenerate.yml or upstream-utils.yml that makes sure the jar file matches the jar file generated from
protoplugin
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll probably add that in a later PR. Right now we need to work on getting this in because we're very broken right now.