diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index e22c616c3b..839266ddea 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -56,16 +56,24 @@ jobs: architecture: x64 task: "build" build-options: "-PciDebugOnly --max-workers 1" + outputs: "build/allOutputs" - os: windows-2019 artifact-name: Win64Release architecture: x64 build-options: "-PciReleaseOnly --max-workers 1" task: "copyAllOutputs" + outputs: "build/allOutputs" - os: macOS-11 artifact-name: macOS architecture: x64 build-options: "-Pbuildalldesktop" task: "build" + outputs: "build/allOutputs" + - os: windows-2019 + artifact-name: Win32 + architecture: x86 + task: ":ntcoreffi:build" + outputs: "ntcoreffi/build/outputs" name: "Build - ${{ matrix.artifact-name }}" runs-on: ${{ matrix.os }} steps: @@ -94,6 +102,9 @@ jobs: run: echo "EXTRA_GRADLE_ARGS=-PreleaseMode" >> $GITHUB_ENV shell: bash if: startsWith(github.ref, 'refs/tags/v') + - name: Set Java Heap Size + run: sed -i 's/-Xmx2g/-Xmx1g/g' gradle.properties + if: matrix.artifact-name == 'Win32' - name: Build with Gradle run: ./gradlew ${{ matrix.task }} --build-cache -PbuildServer -PskipJavaFormat ${{ matrix.build-options }} ${{ env.EXTRA_GRADLE_ARGS }} env: @@ -107,7 +118,7 @@ jobs: - uses: actions/upload-artifact@v2 with: name: ${{ matrix.artifact-name }} - path: build/allOutputs + path: ${{ matrix.outputs }} build-documentation: name: "Build - Documentation" diff --git a/ntcoreffi/build.gradle b/ntcoreffi/build.gradle new file mode 100644 index 0000000000..7a377a75ce --- /dev/null +++ b/ntcoreffi/build.gradle @@ -0,0 +1,90 @@ +plugins { + id 'c' + id 'maven-publish' +} + +apply plugin: 'edu.wpi.first.NativeUtils' + +apply from: '../shared/config.gradle' + +def symbolFile = project.file("src/main/native/symbols.txt") + +nativeUtils { + privateExportsConfigs { + ntcoreffi { + exportsFile = symbolFile + performStripAllSymbols = true + } + } +} + +def generatedHeaders = file("$buildDir/generated/headers") +def generatedFile = file("$buildDir/generated/headers/ExportedSymbols.h") + +def generateSymbols = tasks.register('generateFfiSymbols') { + inputs.file(symbolFile) + outputs.file(generatedFile) + + doLast { + def symbolText = symbolFile as String[] + symbolText = symbolText.collect { + "AddFunctionToLink(${it});" + }.join('\n') + symbolText += '\n' + generatedFile.text = symbolText + } +} + +model { + components { + ntcoreffi(NativeLibrarySpec) { + sources { + c { + source { + srcDirs = ['src/main/native/c'] + includes = ['**/*.c'] + } + exportedHeaders { + srcDir 'src/main/native/include' + srcDir generatedHeaders + } + } + } + binaries.all { binary -> + if (binary instanceof StaticLibraryBinarySpec) { + binary.buildable = false + return + } + binary.tasks.withType(AbstractNativeSourceCompileTask) { + it.dependsOn generateSymbols + } + project(':ntcore').addNtcoreDependency(binary, 'static') + lib project: ':wpinet', library: 'wpinet', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' + } + } + } +} + +def nativeName = 'ntcoreffi' +def baseArtifactId = nativeName +def artifactGroupId = "edu.wpi.first.${nativeName}" +def zipBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-cpp_CLS" + +model { + publishing { + def taskList = createComponentZipTasks($.components, [nativeName], zipBaseName, Zip, project, includeStandardZipFormat) + + publications { + cpp(MavenPublication) { + taskList.each { + artifact it + } + + artifactId = "${baseArtifactId}-cpp" + groupId artifactGroupId + version wpilibVersioning.version.get() + } + } + } +} diff --git a/ntcoreffi/src/main/native/c/ntcoreffi.c b/ntcoreffi/src/main/native/c/ntcoreffi.c new file mode 100644 index 0000000000..66fe9a2a1a --- /dev/null +++ b/ntcoreffi/src/main/native/c/ntcoreffi.c @@ -0,0 +1,11 @@ +// 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. + +#define AddFunctionToLink(FuncName) \ + extern void FuncName(void); \ + FuncName() + +void DoNotCallMeImOnlyForLinking(void) { +#include "ExportedSymbols.h" +} diff --git a/ntcoreffi/src/main/native/symbols.txt b/ntcoreffi/src/main/native/symbols.txt new file mode 100644 index 0000000000..f6b9c862d1 --- /dev/null +++ b/ntcoreffi/src/main/native/symbols.txt @@ -0,0 +1,242 @@ +NT_AddConnectionListener +NT_AddLogger +NT_AddPolledConnectionListener +NT_AddPolledLogger +NT_AddPolledTopicListener +NT_AddPolledTopicListenerMultiple +NT_AddPolledTopicListenerSingle +NT_AddPolledValueListener +NT_AddTopicListener +NT_AddTopicListenerMultiple +NT_AddTopicListenerSingle +NT_AddValueListener +NT_AllocateBooleanArray +NT_AllocateCharArray +NT_AllocateDoubleArray +NT_AllocateFloatArray +NT_AllocateIntegerArray +NT_AllocateStringArray +NT_CreateConnectionListenerPoller +NT_CreateInstance +NT_CreateLoggerPoller +NT_CreateTopicListenerPoller +NT_CreateValueListenerPoller +NT_DeleteTopicProperty +NT_DestroyConnectionListenerPoller +NT_DestroyInstance +NT_DestroyLoggerPoller +NT_DestroyTopicListenerPoller +NT_DestroyValueListenerPoller +NT_DisposeConnectionInfoArray +NT_DisposeConnectionNotification +NT_DisposeConnectionNotificationArray +NT_DisposeLogMessage +NT_DisposeLogMessageArray +NT_DisposeString +NT_DisposeTimestampedBoolean +NT_DisposeTimestampedBooleanArray +NT_DisposeTimestampedDouble +NT_DisposeTimestampedDoubleArray +NT_DisposeTimestampedFloat +NT_DisposeTimestampedFloatArray +NT_DisposeTimestampedInteger +NT_DisposeTimestampedIntegerArray +NT_DisposeTimestampedRaw +NT_DisposeTimestampedString +NT_DisposeTimestampedStringArray +NT_DisposeTopicInfo +NT_DisposeTopicInfoArray +NT_DisposeTopicNotification +NT_DisposeTopicNotificationArray +NT_DisposeValue +NT_DisposeValueArray +NT_DisposeValueNotification +NT_DisposeValueNotificationArray +NT_Flush +NT_FlushLocal +NT_FreeBooleanArray +NT_FreeCharArray +NT_FreeConnectionInfoForTesting +NT_FreeDoubleArray +NT_FreeFloatArray +NT_FreeIntegerArray +NT_FreeQueueBoolean +NT_FreeQueueBooleanArray +NT_FreeQueueDouble +NT_FreeQueueDoubleArray +NT_FreeQueueFloat +NT_FreeQueueFloatArray +NT_FreeQueueInteger +NT_FreeQueueIntegerArray +NT_FreeQueueRaw +NT_FreeQueueString +NT_FreeQueueStringArray +NT_FreeStringArray +NT_FreeTopicInfoForTesting +NT_GetAtomicBoolean +NT_GetAtomicBooleanArray +NT_GetAtomicDouble +NT_GetAtomicDoubleArray +NT_GetAtomicFloat +NT_GetAtomicFloatArray +NT_GetAtomicInteger +NT_GetAtomicIntegerArray +NT_GetAtomicRaw +NT_GetAtomicString +NT_GetAtomicStringArray +NT_GetBoolean +NT_GetBooleanArray +NT_GetConnectionInfoForTesting +NT_GetConnections +NT_GetDefaultInstance +NT_GetDouble +NT_GetDoubleArray +NT_GetEntry +NT_GetEntryEx +NT_GetEntryFlags +NT_GetEntryLastChange +NT_GetEntryName +NT_GetEntryType +NT_GetEntryValue +NT_GetFloat +NT_GetFloatArray +NT_GetInstanceFromHandle +NT_GetInteger +NT_GetIntegerArray +NT_GetNetworkMode +NT_GetRaw +NT_GetString +NT_GetStringArray +NT_GetStringForTesting +NT_GetTopic +NT_GetTopicExists +NT_GetTopicFromHandle +NT_GetTopicInfo +NT_GetTopicInfoForTesting +NT_GetTopicInfos +NT_GetTopicInfosStr +NT_GetTopicName +NT_GetTopicPersistent +NT_GetTopicProperties +NT_GetTopicProperty +NT_GetTopicRetained +NT_GetTopics +NT_GetTopicsStr +NT_GetTopicType +NT_GetTopicTypeString +NT_GetValueBoolean +NT_GetValueBooleanArray +NT_GetValueBooleanArrayForTesting +NT_GetValueBooleanForTesting +NT_GetValueDouble +NT_GetValueDoubleArray +NT_GetValueDoubleArrayForTesting +NT_GetValueDoubleForTesting +NT_GetValueFloat +NT_GetValueFloatArray +NT_GetValueInteger +NT_GetValueIntegerArray +NT_GetValueRaw +NT_GetValueRawForTesting +NT_GetValueString +NT_GetValueStringArray +NT_GetValueStringArrayForTesting +NT_GetValueStringForTesting +NT_GetValueType +NT_InitString +NT_InitValue +NT_IsConnected +NT_Now +NT_Publish +NT_PublishEx +NT_ReadConnectionListenerQueue +NT_ReadLoggerQueue +NT_ReadQueueBoolean +NT_ReadQueueBooleanArray +NT_ReadQueueDouble +NT_ReadQueueDoubleArray +NT_ReadQueueFloat +NT_ReadQueueFloatArray +NT_ReadQueueInteger +NT_ReadQueueIntegerArray +NT_ReadQueueRaw +NT_ReadQueueString +NT_ReadQueueStringArray +NT_ReadQueueValue +NT_ReadQueueValuesBoolean +NT_ReadQueueValuesDouble +NT_ReadQueueValuesFloat +NT_ReadQueueValuesInteger +NT_ReadTopicListenerQueue +NT_ReadValueListenerQueue +NT_Release +NT_ReleaseEntry +NT_RemoveConnectionListener +NT_RemoveLogger +NT_RemoveTopicListener +NT_RemoveValueListener +NT_SetBoolean +NT_SetBooleanArray +NT_SetDefaultBoolean +NT_SetDefaultBooleanArray +NT_SetDefaultDouble +NT_SetDefaultDoubleArray +NT_SetDefaultEntryValue +NT_SetDefaultFloat +NT_SetDefaultFloatArray +NT_SetDefaultInteger +NT_SetDefaultIntegerArray +NT_SetDefaultRaw +NT_SetDefaultString +NT_SetDefaultStringArray +NT_SetDouble +NT_SetDoubleArray +NT_SetEntryFlags +NT_SetEntryValue +NT_SetFloat +NT_SetFloatArray +NT_SetInteger +NT_SetIntegerArray +NT_SetNetworkIdentity +NT_SetNow +NT_SetRaw +NT_SetServer +NT_SetServerMulti +NT_SetServerTeam +NT_SetString +NT_SetStringArray +NT_SetTopicPersistent +NT_SetTopicProperties +NT_SetTopicProperty +NT_SetTopicRetained +NT_StartClient3 +NT_StartClient4 +NT_StartDSClient +NT_StartLocal +NT_StartServer +NT_StopClient +NT_StopDSClient +NT_StopLocal +NT_StopServer +NT_Subscribe +NT_Unpublish +NT_Unsubscribe +WPI_CreateEvent +WPI_CreateSemaphore +WPI_CreateSignalObject +WPI_DestroyEvent +WPI_DestroySemaphore +WPI_DestroySignalObject +WPI_GetSystemTime +WPI_Now +WPI_NowDefault +WPI_ReleaseSemaphore +WPI_ResetEvent +WPI_ResetSignalObject +WPI_SetEvent +WPI_SetNowImpl +WPI_SetSignalObject +WPI_WaitForObject +WPI_WaitForObjectTimeout +WPI_WaitForObjects +WPI_WaitForObjectsTimeout diff --git a/settings.gradle b/settings.gradle index 74a760c55d..816f6ccddc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -51,6 +51,7 @@ include 'wpilibNewCommands' include 'myRobot' include 'docs' include 'msvcruntime' +include 'ntcoreffi' buildCache { def cred = {