Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@n0madic
Copy link

@n0madic n0madic commented Jul 15, 2025

Add static linking support for Codon runtime

This PR introduces static linking capabilities for the Codon runtime library, addressing the need for self-contained executables without external runtime dependencies.

Changes:

  • Added codonrt_static target that builds a static version of the runtime library
  • Created codonrt_static_combined target that combines all dependencies into a single static library
  • Modified writeToExecutable() to prefer static linking when libcodonrt_static_combined.a is available
  • Added platform-specific handling for combining static libraries (libtool on macOS, ar on Linux)
  • Updated install target to include the combined static library

Benefits:

  • Enables creation of standalone executables with no external runtime dependencies
  • Maintains backward compatibility with dynamic linking as fallback
  • Simplifies deployment of Codon applications in containerized or restricted environments

The implementation automatically detects the availability of the static runtime and falls back to dynamic linking if not found, ensuring existing workflows remain unaffected.

Test on MacOS:

% ./build/codon build test_openmp.codon
% otool -L test_openmp
test_openmp:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)
	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.12)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1900.180.0)
% ls -l test_openmp
-rwxr-xr-x@ 1 n0madic  staff  1204568 15 лип 21:39 test_openmp
% ./test_openmp
Thread 5Thread 3
Thread 9
Thread 8
Thread 4
Thread 7
Thread 2
Thread 0
Thread 1
Thread 6

Copilot AI review requested due to automatic review settings July 15, 2025 18:41
@cla-bot
Copy link

cla-bot bot commented Jul 15, 2025

Thank you for your pull request. We require contributors to agree to our Contributor License Agreement (https://exaloop.io/legal/cla), and we don't have @bhanuprasad14 on file. In order for us to review and merge your code, please email [email protected] to get yourself added.

Copy link

Copilot AI left a comment

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 adds static linking support for the Codon runtime library, enabling fully self-contained executables, while preserving dynamic linking as a fallback.

  • Introduces codonrt_static and codonrt_static_combined CMake targets to build and merge static runtime dependencies
  • Updates LLVMVisitor::writeToExecutable to detect and link against libcodonrt_static_combined.a when available
  • Extends the install rules to include the combined static library

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
codon/cir/llvm/llvisitor.cpp Detects and links the combined static Codon runtime library in writeToExecutable()
CMakeLists.txt Defines static runtime library targets, platform-specific combination commands, and installs the combined archive
Comments suppressed due to low confidence (1)

codon/cir/llvm/llvisitor.cpp:558

  • [nitpick] Consider renaming codonrtStatic to codonrtStaticPath (or similar) to clarify that this variable holds a filesystem path.
  std::string codonrtStatic = "";

@K0lb3 K0lb3 mentioned this pull request Aug 20, 2025
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.

1 participant