Skip to content

Conversation

Copy link

Copilot AI commented Oct 19, 2025

Problem

The build fails with cryptic errors when an older Go version (< 1.21) is used, because the oci-go/go.mod file requires features that were introduced in Go 1.21:

go: errors parsing go.mod:
/home/runner/work/llama.cpp/llama.cpp/oci-go/go.mod:3: invalid go version '1.24.0': must match format 1.23
/home/runner/work/llama.cpp/llama.cpp/oci-go/go.mod:5: unknown directive: toolchain
gmake[2]: *** [common/CMakeFiles/oci_go_lib.dir/build.make:75: /home/runner/work/llama.cpp/llama.cpp/oci-go/liboci.a] Error 1

The error occurs during the build phase, making it difficult to diagnose. Users with older Go installations would see the build fail partway through with confusing error messages.

Solution

Added a Go version check in common/CMakeLists.txt that runs before attempting to build the OCI library. The check:

  1. Executes go version to get the installed Go version
  2. Parses the version to extract major and minor version numbers
  3. Verifies Go 1.21 or later is installed (required for toolchain directive support)
  4. Shows a clear warning if the version is too old
  5. Gracefully skips OCI library build when requirements aren't met
  6. Allows the rest of the build to continue normally

Implementation Details

The version check handles various Go version formats (1.21, 1.21.0, 1.22rc1, etc.) and includes proper error handling for:

  • Failed go version command execution
  • Unparseable version strings
  • Missing Go compiler

When Go < 1.21 is detected, users now see a clear message:

CMake Warning: Go version 1.20 is too old. OCI functionality requires Go 1.21 or later. OCI functionality will not be available.

The build then continues successfully without OCI support, rather than failing with cryptic errors.

Testing

  • ✅ Verified build works with Go 1.24.9
  • ✅ Verified warning shown with Go 1.20
  • ✅ Verified build continues without OCI when Go is too old
  • ✅ Tested various version formats and edge cases
  • ✅ Confirmed existing tests still pass

Impact

This change ensures that:

  • Users with older Go versions get a clear, actionable error message
  • The build doesn't fail halfway through with confusing errors
  • OCI functionality is automatically disabled when requirements aren't met
  • Users without Go or with incompatible versions can still build llama.cpp for other use cases
Original prompt

The go version needs to be checked before we build in the go code:

-- Generating done (0.4s)
-- Build files have been written to: /home/runner/work/llama.cpp/llama.cpp/build
[ 0%] Building CXX object common/CMakeFiles/build_info.dir/build-info.cpp.o
[ 0%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml.c.o
[ 0%] Building C object examples/gguf-hash/CMakeFiles/sha256.dir/deps/sha256/sha256.c.o
[ 1%] Building OCI Go library
[ 1%] Built target build_info
[ 2%] Building C object examples/gguf-hash/CMakeFiles/xxhash.dir/deps/xxhash/xxhash.c.o
[ 2%] Built target sha256
[ 2%] Building C object examples/gguf-hash/CMakeFiles/sha1.dir/deps/sha1/sha1.c.o
[ 2%] Built target xxhash
[ 2%] Building CXX object tools/mtmd/CMakeFiles/llama-llava-cli.dir/deprecation-warning.cpp.o
go: errors parsing go.mod:
/home/runner/work/llama.cpp/llama.cpp/oci-go/go.mod:3: invalid go version '1.24.0': must match format 1.23
/home/runner/work/llama.cpp/llama.cpp/oci-go/go.mod:5: unknown directive: toolchain
gmake[2]: *** [common/CMakeFiles/oci_go_lib.dir/build.make:75: /home/runner/work/llama.cpp/llama.cpp/oci-go/liboci.a] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:2416: common/CMakeFiles/oci_go_lib.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
[ 2%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml.cpp.o
[ 2%] Built target sha1
[ 3%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml-alloc.c.o
[ 3%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml-backend.cpp.o
[ 3%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml-opt.cpp.o
[ 4%] Linking CXX executable ../../bin/llama-llava-cli
[ 5%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml-threading.cpp.o
[ 5%] Built target llama-llava-cli
[ 5%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml-quants.c.o
[ 6%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/gguf.cpp.o
[ 6%] Linking CXX shared library ../../bin/libggml-base.so
[ 6%] Built target ggml-base
gmake: *** [Makefile:146: all] Error 2


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

ericcurtin and others added 2 commits October 19, 2025 20:51
So we can pull from any OCI registry, add authentication, etc.

Add docker-style progress bars and resumable downloads to OCI pulls

Update documentation with progress bars and resumable downloads info

Make OCI Go build optional and skip editorconfig for oci-go

Signed-off-by: Eric Curtin <[email protected]>
Copilot AI changed the title [WIP] Check Go version before build process Add Go version check before building OCI library to prevent build failures Oct 19, 2025
Copilot AI requested a review from ericcurtin October 19, 2025 20:14
Copilot finished work on behalf of ericcurtin October 19, 2025 20:14
@ericcurtin ericcurtin force-pushed the integrate-go-containerregistry-library branch 3 times, most recently from e4b192d to 2935963 Compare October 19, 2025 20:47
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