Skip to content

Commit

Permalink
Remove unused native libs from opencv (#12021)
Browse files Browse the repository at this point in the history
* Remove native libs of opencv or different platforms

* Fix Mac os name

* Include Mac native libs in signing
  • Loading branch information
Akirathan authored Jan 10, 2025
1 parent 7d9d69b commit 354ccce
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/ide-desktop/client/tasks/signArchivesMacOs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ async function ensoPackageSignables(resourcesDir: string): Promise<Signable[]> {
['META-INF/native/libconscrypt_openjdk_jni-osx-*.dylib'],
],
['lib/Standard/Tableau/*/polyglot/java/jna-*.jar', ['com/sun/jna/*/libjnidispatch.jnilib']],
[
'lib/Standard/Image/*/polyglot/java/opencv-*.jar',
['nu/pattern/opencv/osx/*/libopencv_java*.dylib'],
],
]
return ArchiveToSign.lookupMany(engineDir, archivePatterns)
const binariesPattern = 'lib/Standard/Image/*/polyglot/lib/*.dylib'

const binaries = await BinaryToSign.lookupMany(engineDir, [binariesPattern])
const archives = await ArchiveToSign.lookupMany(engineDir, archivePatterns)
return [...archives, ...binaries]
}

// ================
Expand Down
32 changes: 31 additions & 1 deletion project/StdBits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sbt.io.IO
import sbt.librarymanagement.{ConfigurationFilter, DependencyFilter}

import java.io.File
import java.util.Locale

object StdBits {

Expand Down Expand Up @@ -132,7 +133,10 @@ object StdBits {
if (
strippedEntryName.contains("linux/ARM") ||
strippedEntryName.contains("linux/x86_32") ||
strippedEntryName.contains("README.md")
strippedEntryName.contains("README.md") ||
// Remove native libs for different platforms
(!strippedEntryName.contains(osName())) ||
(!strippedEntryName.contains(arch()))
) {
None
} else {
Expand Down Expand Up @@ -171,6 +175,32 @@ object StdBits {
)
}

/** Inspired by `org.enso.pkg.NativeLibraryFinder`
*/
private def osName(): String = {
var osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH)
if (osName.contains(" ")) {
// Strip version
osName = osName.substring(0, osName.indexOf(' '))
}
if (osName.contains("linux")) {
"linux"
} else if (osName.contains("mac")) {
"osx"
} else if (osName.contains("windows")) {
"windows"
} else {
throw new IllegalStateException(s"Unsupported OS: $osName")
}
}

/** Inspired by `org.enso.pkg.NativeLibraryFinder`
*/
private def arch(): String = {
val arch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH)
arch.replace("amd64", "x86_64")
}

private def updateDependency(
jar: File,
destinationDir: File,
Expand Down

0 comments on commit 354ccce

Please sign in to comment.