Skip to content

Limit symbol visibility in the shared libraries - #2822

Merged
csukuangfj merged 5 commits into
k2-fsa:masterfrom
csukuangfj:fix-symbol-vis
Nov 25, 2025
Merged

csukuangfj merged 5 commits into
k2-fsa:masterfrom
csukuangfj:fix-symbol-vis

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Nov 25, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Chores
    • Updated build system configuration for symbol visibility and linker behavior across platforms (Android, Unix, macOS).

✏️ Tip: You can customize this high-level summary in your review settings.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 25, 2025
@coderabbitai

coderabbitai Bot commented Nov 25, 2025 •

Copy link
Copy Markdown

Walkthrough

Adds platform-specific linker configuration for symbol visibility control to C API and JNI libraries using linker scripts for Android/Unix and exported symbol lists for Apple platforms.

Changes

Cohort / File(s) Summary
C API linker configuration
sherpa-onnx/c-api/CMakeLists.txt, sherpa-onnx/c-api/generate.sh, sherpa-onnx/c-api/sherpa-onnx-symbols-c.exp, sherpa-onnx/c-api/sherpa-onnx-symbols-c.lds
Adds platform-specific linker flags to sherpa-onnx-c-api target: version script (sherpa-onnx-symbols-c.lds) for Android/Unix, exported_symbols_list (sherpa-onnx-symbols-c.exp) for Apple. Includes shell script to extract exported C symbols from compiled library. Symbol list covers creation, destruction, processing routines for punctuation, streams (offline/online), audio tagging, circular buffers, speaker embeddings, language identification, voice activity detection, and TTS components.
JNI linker configuration
sherpa-onnx/jni/CMakeLists.txt, sherpa-onnx/jni/generate.sh, sherpa-onnx/jni/sherpa-onnx-symbols.exp, sherpa-onnx/jni/sherpa-onnx-symbols.lds
Applies parallel platform-specific linker configuration to sherpa-onnx-jni target with version script (sherpa-onnx-symbols.lds) for Android/Unix and exported_symbols_list (sherpa-onnx-symbols.exp) for Apple. Includes shell script to extract JNI symbols matching Java_com_k2fsa_sherpa_onnx prefix. Symbol list enumerates JNI native methods for AudioTagging, KeywordSpotter, Offline/Online recognizers and streams, Punctuation, Speaker embedding, Language identification, VAD, TTS, and utility operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify CMakeLists.txt linker flag syntax and conditional logic for platform-specific behavior (Android/Unix vs Apple)
  • Validate linker script syntax (symbol patterns and scope sections)
  • Confirm symbol names in .exp files match actual C/JNI API function names
  • Review shell script logic for nm symbol extraction and filtering correctness
  • Ensure consistency of symbol prefixes across platform-specific files (SherpaOnnx* and SherpaOffline* for C API, Java_com_k2fsa_sherpa_onnx* for JNI)

Possibly related PRs

Suggested labels

size:XL

Poem

🐰 With symbols sorted, scripts aligned,
We tame the linker, one by one confined,
On Android, macOS, Unix too—
Each platform gets the exports true!
Visibility controlled with care,
So public APIs shine in air.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Limit symbol visibility in the shared libraries' clearly and specifically describes the main purpose of the changeset: implementing platform-specific linker configurations to control which symbols are exported from shared libraries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @csukuangfj, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the build process for the sherpa-onnx shared libraries by introducing explicit symbol visibility control. This change aims to improve library encapsulation, prevent symbol conflicts with other loaded libraries, and potentially optimize library size and load performance by only exposing necessary public API symbols.

Highlights

  • Symbol Visibility Control: Implemented explicit control over symbol visibility for sherpa-onnx-c-api and sherpa-onnx-jni shared libraries to improve encapsulation and prevent symbol conflicts.
  • Platform-Specific Linker Flags: Configured CMakeLists.txt to apply platform-specific linker flags (--version-script for Android/Unix and -exported_symbols_list for Apple) to manage which symbols are exported.
  • New Symbol Definition Files: Introduced .lds (linker script) files for Android/Unix and .exp (exported symbols list) files for Apple to precisely define the public API surface of the shared libraries.
  • Automated Symbol Export Generation: Added generate.sh scripts to automate the creation of .exp files for Apple platforms by extracting public symbols from the compiled libraries.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@csukuangfj
csukuangfj requested a review from Copilot November 25, 2025 06:18

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable optimization by limiting symbol visibility in the shared libraries for Linux, Android, and macOS. This should help reduce binary size and improve loading times. The approach using linker scripts and exported symbol lists is sound. My review includes a couple of suggestions to improve the maintainability of the newly added generate.sh scripts by parameterizing hardcoded paths and refining a pattern match, making them more robust for future development.

Comment on lines +1 to +5
#!/usr/bin/env bash
set -ex

nm -g ../../build/lib/libsherpa-onnx-c-api.dylib | awk '$2=="T" && $3 ~ /^_Sherpa/ {print $3}' | sort > ./sherpa-onnx-symbols-c.exp

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability, it's better to avoid hardcoding the path to the dylib. The current path ../../build/lib/libsherpa-onnx-c-api.dylib is brittle as it assumes a specific build directory structure. A more robust approach is to pass the library path as a command-line argument to the script.

Suggested change
#!/usr/bin/env bash
set -ex
nm -g ../../build/lib/libsherpa-onnx-c-api.dylib | awk '$2=="T" && $3 ~ /^_Sherpa/ {print $3}' | sort > ./sherpa-onnx-symbols-c.exp
#!/usr/bin/env bash
set -ex
if [ $# -ne 1 ]; then
echo "Usage: $0 /path/to/libsherpa-onnx-c-api.dylib"
exit 1
fi
dylib_path="$1"
nm -g "${dylib_path}" | awk '$2=="T" && $3 ~ /^_Sherpa/ {print $3}' | sort > ./sherpa-onnx-symbols-c.exp

Comment on lines +1 to +5
#!/usr/bin/env bash
set -ex

nm -g ../../build/lib/libsherpa-onnx-jni.dylib | awk '$2=="T" && $3 ~ /^_Java_com_k2fsa/ {print $3}' | sort > ./sherpa-onnx-symbols.exp

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This script can be improved for better maintainability in two ways:

  1. Avoid Hardcoded Path: The path ../../build/lib/libsherpa-onnx-jni.dylib is hardcoded, which is brittle. It's better to pass the path as a script argument.
  2. More Specific awk Pattern: The pattern ^_Java_com_k2fsa is a bit too broad. Using a more specific pattern like ^_Java_com_k2fsa_sherpa_onnx_ would be more precise and safer for future changes.

Here is a suggested version that addresses both points:

Suggested change
#!/usr/bin/env bash
set -ex
nm -g ../../build/lib/libsherpa-onnx-jni.dylib | awk '$2=="T" && $3 ~ /^_Java_com_k2fsa/ {print $3}' | sort > ./sherpa-onnx-symbols.exp
#!/usr/bin/env bash
set -ex
if [ $# -ne 1 ]; then
echo "Usage: $0 /path/to/libsherpa-onnx-jni.dylib"
exit 1
fi
dylib_path="$1"
nm -g "${dylib_path}" | awk '$2=="T" && $3 ~ /^_Java_com_k2fsa_sherpa_onnx_/ {print $3}' | sort > ./sherpa-onnx-symbols.exp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
sherpa-onnx/jni/CMakeLists.txt (1)

51-59: JNI symbol visibility wiring looks correct; consider target_link_options later

The platform conditions and linker flag wiring to sherpa-onnx-symbols.lds / .exp look sound and match the new scripts. For future cleanup, you might prefer target_link_options(sherpa-onnx-jni PRIVATE "LINKER:…") over LINK_FLAGS, but this is not blocking.

sherpa-onnx/c-api/generate.sh (1)

1-5: Mac-only helper script is fine; optionally parameterize the library path

The nm | awk | sort pipeline is straightforward and matches the _Sherpa* naming scheme. If you plan to use this more widely, consider accepting the library path as an argument or documenting that it’s macOS-only and assumes ../../build/lib/libsherpa-onnx-c-api.dylib.

sherpa-onnx/jni/sherpa-onnx-symbols.lds (1)

1-6: Consider explicitly exporting JNI_OnLoad / JNI_OnUnload for robustness

The version script nicely restricts exports to Java_com_k2fsa_sherpa_onnx*. If you ever add JNI_OnLoad / JNI_OnUnload, they’ll currently be hidden. It’s cheap and safe to future‑proof by adding them to global::

{
  global:
    Java_com_k2fsa_sherpa_onnx*;
+   JNI_OnLoad;
+   JNI_OnUnload;
  local:
    *;
};
sherpa-onnx/c-api/CMakeLists.txt (1)

15-23: C API symbol visibility config is consistent; could be scoped to shared builds

The linker script hookup for sherpa-onnx-c-api looks correct and matches the JNI approach. To make intent clearer, you might move this block inside the existing if(BUILD_SHARED_LIBS) or switch to target_link_options so it’s explicit that it only matters for shared libraries.

sherpa-onnx/jni/sherpa-onnx-symbols.exp (1)

1-110: Symbol list looks consistent; consider automating drift checks

The _Java_com_k2fsa_sherpa_onnx_* entries look consistent with the JNI surface. To avoid future drift, it’d be helpful to standardize on regenerating this via generate.sh (or add a simple CI check that nm output matches this list). Also, if you introduce JNI_OnLoad/JNI_OnUnload at some point, remember to add them here as well as to the version script.

sherpa-onnx/c-api/sherpa-onnx-symbols-c.exp (1)

1-149: C API export list aligns with naming scheme; keep it in sync with generate.sh

The _SherpaOffline* / _SherpaOnnx* entries look coherent and match the prefixes used in the version script and generator. As you evolve the C API, it’d be good to standardize on regenerating or validating this list via c-api/generate.sh so newly added public functions don’t get accidentally hidden (or vice versa).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1c458b and 7907af6.

📒 Files selected for processing (8)
  • sherpa-onnx/c-api/CMakeLists.txt (1 hunks)
  • sherpa-onnx/c-api/generate.sh (1 hunks)
  • sherpa-onnx/c-api/sherpa-onnx-symbols-c.exp (1 hunks)
  • sherpa-onnx/c-api/sherpa-onnx-symbols-c.lds (1 hunks)
  • sherpa-onnx/jni/CMakeLists.txt (1 hunks)
  • sherpa-onnx/jni/generate.sh (1 hunks)
  • sherpa-onnx/jni/sherpa-onnx-symbols.exp (1 hunks)
  • sherpa-onnx/jni/sherpa-onnx-symbols.lds (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-06T04:18:47.981Z
Learnt from: litongjava
Repo: k2-fsa/sherpa-onnx PR: 2440
File: sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/core/Core.java:4-6
Timestamp: 2025-08-06T04:18:47.981Z
Learning: In sherpa-onnx Java API, the native library names in Core.java (WIN_NATIVE_LIBRARY_NAME = "sherpa-onnx-jni.dll", UNIX_NATIVE_LIBRARY_NAME = "libsherpa-onnx-jni.so", MACOS_NATIVE_LIBRARY_NAME = "libsherpa-onnx-jni.dylib") are copied directly from the compiled binary filenames and should not be changed to match other libraries' naming conventions.

Applied to files:

  • sherpa-onnx/c-api/generate.sh
  • sherpa-onnx/jni/sherpa-onnx-symbols.lds
  • sherpa-onnx/jni/generate.sh
  • sherpa-onnx/jni/CMakeLists.txt
  • sherpa-onnx/c-api/CMakeLists.txt
  • sherpa-onnx/jni/sherpa-onnx-symbols.exp
📚 Learning: 2025-08-06T04:23:50.237Z
Learnt from: litongjava
Repo: k2-fsa/sherpa-onnx PR: 2440
File: sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/core/Core.java:4-6
Timestamp: 2025-08-06T04:23:50.237Z
Learning: The sherpa-onnx JNI library files are stored in Hugging Face repository at https://huggingface.co/csukuangfj/sherpa-onnx-libs under versioned directories like jni/1.12.7/, and the actual Windows JNI library filename is "sherpa-onnx-jni.dll" as defined in Core.java constants.

Applied to files:

  • sherpa-onnx/jni/sherpa-onnx-symbols.lds
  • sherpa-onnx/jni/generate.sh
  • sherpa-onnx/jni/CMakeLists.txt
  • sherpa-onnx/c-api/CMakeLists.txt
  • sherpa-onnx/c-api/sherpa-onnx-symbols-c.lds
  • sherpa-onnx/jni/sherpa-onnx-symbols.exp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: ubuntu-latest Release static tts-ON
  • GitHub Check: ubuntu-latest Debug shared tts-ON
  • GitHub Check: ubuntu-latest Debug shared tts-OFF
  • GitHub Check: rknn shared ON
  • GitHub Check: ubuntu-latest Release shared tts-ON
  • GitHub Check: ubuntu-latest Release static tts-OFF
  • GitHub Check: rknn shared OFF
  • GitHub Check: Debug shared-OFF tts-ON
  • GitHub Check: Debug shared-ON tts-ON
  • GitHub Check: Debug shared-OFF tts-OFF
  • GitHub Check: Release shared-OFF tts-ON
  • GitHub Check: Debug shared-ON tts-OFF
  • GitHub Check: Release shared-ON tts-OFF
  • GitHub Check: Release shared-ON tts-ON
  • GitHub Check: Release shared-OFF tts-OFF
  • GitHub Check: Debug shared tts-ON
  • GitHub Check: Release shared tts-OFF
  • GitHub Check: Release static tts-OFF
  • GitHub Check: Release static tts-ON
🔇 Additional comments (2)
sherpa-onnx/c-api/sherpa-onnx-symbols-c.lds (1)

1-8: Version script looks good; ensure prefixes are reserved for public C API

Restricting exports to SherpaOnnx* and SherpaOffline* is a reasonable convention and aligns with the .exp list. Just make sure those prefixes are reserved for public C API symbols so you don’t accidentally export internal helpers on Linux/Android that aren’t present in the macOS list.

sherpa-onnx/jni/generate.sh (1)

1-5: JNI export generator is fine; be aware of macOS-only and JNI_OnLoad

The script correctly captures _Java_com_k2fsa… JNI entrypoints for the .exp list. If you ever rely on JNI_OnLoad / JNI_OnUnload, you’ll need to add them manually (they won’t be picked up by this filter) and keep them in sync with the version script.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements symbol visibility control for shared libraries to limit the exposed symbols to only those necessary for JNI and C API consumers. This reduces symbol pollution, minimizes the risk of symbol conflicts, and can potentially improve dynamic linker performance.

Key changes:

  • Added linker version scripts (.lds) for Linux/Android and exported symbol lists (.exp) for macOS
  • Added helper shell scripts to generate symbol export lists from built libraries
  • Updated CMakeLists.txt files to apply symbol visibility constraints at link time

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sherpa-onnx/jni/sherpa-onnx-symbols.lds Linker version script for JNI library limiting visibility to Java_com_k2fsa_sherpa_onnx* symbols on Linux/Android
sherpa-onnx/jni/sherpa-onnx-symbols.exp macOS exported symbols list for JNI library containing 110 JNI native method symbols
sherpa-onnx/jni/generate.sh Helper script to extract JNI symbols from built macOS library
sherpa-onnx/jni/CMakeLists.txt Applies linker version script on Linux/Android and export list on macOS for JNI library
sherpa-onnx/c-api/sherpa-onnx-symbols-c.lds Linker version script for C API library limiting visibility to SherpaOnnx* and SherpaOffline* symbols
sherpa-onnx/c-api/sherpa-onnx-symbols-c.exp macOS exported symbols list for C API library containing 149 C API function symbols
sherpa-onnx/c-api/generate.sh Helper script to extract C API symbols from built macOS library
sherpa-onnx/c-api/CMakeLists.txt Applies linker version script on Linux/Android and export list on macOS for C API library

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +52 to +57
set_target_properties(sherpa-onnx-jni PROPERTIES
LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols.lds"
)
elseif(APPLE)
set_target_properties(sherpa-onnx-jni PROPERTIES
LINK_FLAGS "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols.exp"

Copilot AI Nov 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LINK_FLAGS property is deprecated in modern CMake. Consider using target_link_options() instead for better compatibility with CMake 3.13+. For example:

if(ANDROID OR (UNIX AND NOT APPLE))
  target_link_options(sherpa-onnx-jni PRIVATE
    "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols.lds"
  )
elseif(APPLE)
  target_link_options(sherpa-onnx-jni PRIVATE
    "LINKER:-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols.exp"
  )
endif()

This provides better shell escaping and is the recommended approach.

Suggested change
set_target_properties(sherpa-onnx-jni PROPERTIES
LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols.lds"
)
elseif(APPLE)
set_target_properties(sherpa-onnx-jni PROPERTIES
LINK_FLAGS "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols.exp"
target_link_options(sherpa-onnx-jni PRIVATE
"LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols.lds"
)
elseif(APPLE)
target_link_options(sherpa-onnx-jni PRIVATE
"LINKER:-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols.exp"

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +21
set_target_properties(sherpa-onnx-c-api PROPERTIES
LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols-c.lds"
)
elseif(APPLE)
set_target_properties(sherpa-onnx-c-api PROPERTIES
LINK_FLAGS "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols-c.exp"

Copilot AI Nov 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LINK_FLAGS property is deprecated in modern CMake. Consider using target_link_options() instead for better compatibility with CMake 3.13+. For example:

if(ANDROID OR (UNIX AND NOT APPLE))
  target_link_options(sherpa-onnx-c-api PRIVATE
    "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols-c.lds"
  )
elseif(APPLE)
  target_link_options(sherpa-onnx-c-api PRIVATE
    "LINKER:-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols-c.exp"
  )
endif()

This provides better shell escaping and is the recommended approach.

Suggested change
set_target_properties(sherpa-onnx-c-api PROPERTIES
LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols-c.lds"
)
elseif(APPLE)
set_target_properties(sherpa-onnx-c-api PROPERTIES
LINK_FLAGS "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols-c.exp"
target_link_options(sherpa-onnx-c-api PRIVATE
"LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols-c.lds"
)
elseif(APPLE)
target_link_options(sherpa-onnx-c-api PRIVATE
"LINKER:-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx-symbols-c.exp"

Copilot uses AI. Check for mistakes.
#!/usr/bin/env bash
set -ex

nm -g ../../build/lib/libsherpa-onnx-jni.dylib | awk '$2=="T" && $3 ~ /^_Java_com_k2fsa/ {print $3}' | sort > ./sherpa-onnx-symbols.exp

Copilot AI Nov 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script hardcodes the macOS library path and extension (.dylib), making it platform-specific. Consider adding platform detection or documenting that this script is macOS-only. Alternatively, make the script more portable:

if [[ "$OSTYPE" == "darwin"* ]]; then
  LIB_EXT="dylib"
else
  LIB_EXT="so"
fi
nm -g ../../build/lib/libsherpa-onnx-jni.${LIB_EXT} | awk '$2=="T" && $3 ~ /^_Java_com_k2fsa/ {print $3}' | sort > ./sherpa-onnx-symbols.exp

Note that on Linux, the underscore prefix may not be present in symbol names.

Suggested change
nm -g ../../build/lib/libsherpa-onnx-jni.dylib | awk '$2=="T" && $3 ~ /^_Java_com_k2fsa/ {print $3}' | sort > ./sherpa-onnx-symbols.exp
if [[ "$OSTYPE" == "darwin"* ]]; then
LIB_EXT="dylib"
SYMBOL_PREFIX="_"
else
LIB_EXT="so"
SYMBOL_PREFIX=""
fi
nm -g ../../build/lib/libsherpa-onnx-jni.${LIB_EXT} | awk -v prefix="$SYMBOL_PREFIX" '$2=="T" && $3 ~ ("^" prefix "Java_com_k2fsa") {print $3}' | sort > ./sherpa-onnx-symbols.exp

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +5
nm -g ../../build/lib/libsherpa-onnx-c-api.dylib | awk '$2=="T" && $3 ~ /^_Sherpa/ {print $3}' | sort > ./sherpa-onnx-symbols-c.exp

Copilot AI Nov 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script hardcodes the macOS library path and extension (.dylib), making it platform-specific. Consider adding platform detection or documenting that this script is macOS-only. Alternatively, make the script more portable:

if [[ "$OSTYPE" == "darwin"* ]]; then
  LIB_EXT="dylib"
else
  LIB_EXT="so"
fi
nm -g ../../build/lib/libsherpa-onnx-c-api.${LIB_EXT} | awk '$2=="T" && $3 ~ /^_Sherpa/ {print $3}' | sort > ./sherpa-onnx-symbols-c.exp

Note that on Linux, the underscore prefix may not be present in symbol names.

Suggested change
nm -g ../../build/lib/libsherpa-onnx-c-api.dylib | awk '$2=="T" && $3 ~ /^_Sherpa/ {print $3}' | sort > ./sherpa-onnx-symbols-c.exp
# Detect platform and set library extension and symbol prefix
if [[ "$OSTYPE" == "darwin"* ]]; then
LIB_EXT="dylib"
SYMBOL_PREFIX="_Sherpa"
else
LIB_EXT="so"
SYMBOL_PREFIX="Sherpa"
fi
nm -g ../../build/lib/libsherpa-onnx-c-api.${LIB_EXT} | awk -v prefix="$SYMBOL_PREFIX" '$2=="T" && $3 ~ ("^" prefix) {print $3}' | sort > ./sherpa-onnx-symbols-c.exp

Copilot uses AI. Check for mistakes.
@csukuangfj
csukuangfj merged commit 9871306 into k2-fsa:master Nov 25, 2025
17 of 43 checks passed
@csukuangfj
csukuangfj deleted the fix-symbol-vis branch November 25, 2025 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants