Skip to content

Fix BUILD_GEMMA_DLL CMake build, install paths, and C/C# bindings - #1083

Open
akamilkhan wants to merge 1 commit into
google:devfrom
akamilkhan:fix-dll-build-and-bindings
Open

akamilkhan wants to merge 1 commit into
google:devfrom
akamilkhan:fix-dll-build-and-bindings

Conversation

@akamilkhan

Copy link
Copy Markdown

Summary

Fixes several build, installation, and binding signature issues in the C API / shared library target (BUILD_GEMMA_DLL / gemma/bindings/):

  • CMakeLists.txt:
    • Link nlohmann_json::nlohmann_json into gemma_shared to match libgemma (required since deepseek/dsv4_tokenizer.cc in ${SOURCES} includes <nlohmann/json.hpp>).
    • Update the BUILD_GEMMA_DLL install(FILES ...) paths from the non-existent gemma/c_api.h and gemma/GemmaInterop.cs locations to gemma/bindings/c_api.h, gemma/bindings/context.h, and gemma/bindings/GemmaInterop.cs.
  • CMakePresets.json:
    • Add "CMAKE_POLICY_VERSION_MINIMUM": "3.5" to the windows-dll configure preset (matching the windows preset so CMake 4.x configures sentencepiece).
  • gemma/bindings/c_api.h:
    • Add missing GEMMA_API declarations for GemmaSetMaxGeneratedTokens and GemmaSetPrefillTbatchSize (already defined in gemma/bindings/c_api.cc and imported in GemmaInterop.cs).
  • gemma/bindings/context.cc:
    • Guard against null tokenizer_path / weights_path in GemmaContext::Create before constructing LoaderArgs(const std::string&, const std::string&) (preventing undefined behavior when tokenizer_path is NULL for single-file .sbs weights), and remove duplicate threading_args.spin assignment.
  • gemma/bindings/GemmaInterop.cs:
    • Update the [DllImport("gemma")] declaration of GemmaCreate from the obsolete 5-parameter signature to the 3-parameter signature (tokenizerPath, weightsPath, maxGeneratedTokens) matching c_api.h and the Gemma constructor call site.

- Link nlohmann_json::nlohmann_json into gemma_shared in CMakeLists.txt to match libgemma (required by deepseek/dsv4_tokenizer.cc in SOURCES).
- Fix BUILD_GEMMA_DLL install paths to point to gemma/bindings/c_api.h, gemma/bindings/context.h, and gemma/bindings/GemmaInterop.cs.
- Add CMAKE_POLICY_VERSION_MINIMUM='3.5' to the windows-dll CMake preset to match the windows preset for sentencepiece compatibility.
- Declare GemmaSetMaxGeneratedTokens and GemmaSetPrefillTbatchSize in gemma/bindings/c_api.h to match c_api.cc and GemmaInterop.cs.
- Guard against null tokenizer_path/weights_path in GemmaContext::Create and remove duplicate threading_args.spin assignment.
- Update the GemmaCreate DllImport signature in GemmaInterop.cs to match the 3-parameter C API and constructor call site.
@google-cla

google-cla Bot commented Nov 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@jan-wassenberg

Copy link
Copy Markdown
Member

Thanks for the change. Are you able to sign the CLA?
Also, based on the description, not sure we should change the method signatures in .cs, we may still have some callers using the current 5 args.

@akamilkhan

Copy link
Copy Markdown
Author

Signed the CLA and rescanned, thanks!

On GemmaInterop.cs: GemmaCreate is just the private P/Invoke declaration ([DllImport("gemma")])—not a public method. The public Gemma(...) constructor and c_api.h/c_api.cc already take 3 args (from an earlier commit 20757046 that missed updating the DllImport declaration), so GemmaInterop.cs currently doesn't compile because the constructor calls a 5-arg DllImport with 3 args.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants