### JuliaC CLI: Version and Help Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/INDEX.md Command-line interface examples to check the installed JuliaC version and display help information. ```bash juliac --version ``` ```bash juliac --help ``` -------------------------------- ### Quick Start without App Install: Compile Executable Source: https://github.com/julialang/juliac.jl/blob/main/README.md Compile an executable without installing JuliaC as an app, by directly invoking its `main` function via `julia -e`. ```julia julia --project -e "using JuliaC; JuliaC.main(ARGS)" -- \ --output-exe app_test_exe \ --bundle build \ --trim=safe \ --experimental \ test/AppProject ``` -------------------------------- ### Quick Start CLI: Compile Executable Bundle Source: https://github.com/julialang/juliac.jl/blob/main/README.md Compile an executable and create a self-contained bundle using the `juliac` CLI. Requires a project with a `@main` function. ```bash juliac \ --output-exe app_test_exe \ --bundle build \ --trim=safe \ --experimental \ test/AppProject ``` -------------------------------- ### C Usage Example Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/types-and-abi.md An example of how to use the exported 'distance' function and 'Point' struct in a C program, including basic I/O. ```c #include "mylib.h" int main() { Point p1 = {3, 4.0}; Point p2 = {0, 0.0}; double dist = distance(p1, p2); printf("Distance: %f\n", dist); return 0; } ``` -------------------------------- ### Check JuliaC Versions Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/configuration.md Display the installed version of JuliaC or get help information. ```bash # Check versions juliac --version juliac --help ``` -------------------------------- ### Complete Bundle Recipe Example Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-recipe.md Demonstrates compiling, linking, and bundling a Julia application into an executable with specified output type, file, trim mode, verbosity, output name, and directory structure. This is useful for creating self-contained applications. ```julia using JuliaC # Compile → Link → Bundle in one go img = ImageRecipe( output_type = "--output-exe", file = "test/AppProject", trim_mode = "safe", verbose = true, ) link = LinkRecipe( image_recipe = img, outname = "myapp", ) bun = BundleRecipe( link_recipe = link, output_dir = "build", libdir = "lib", privatize = false, ) compile_products(img) link_products(link) bundle_products(bun) ``` -------------------------------- ### JuliaC CLI: Executable with Bundling Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/INDEX.md Command-line interface example for creating an executable with a bundled distribution. Use the `--bundle` and `--trim` flags for optimization. ```bash juliac --output-exe myapp --bundle dist --trim=safe src/app ``` -------------------------------- ### Information Option: Version Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/configuration.md Print the version information for both JuliaC and the underlying Julia installation. ```bash --version ``` -------------------------------- ### Install JuliaC App Source: https://github.com/julialang/juliac.jl/blob/main/README.md Install JuliaC as a Julia app using the package manager. Enable app shims for direct CLI access. ```julia pkg> app add JuliaC ``` ```bash echo 'export PATH="$HOME/.julia/bin:$PATH"' >> ~/.bashrc # adapt for your shell ``` -------------------------------- ### Compile and Link Sysimage Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-link-products.md This example illustrates how to compile a Julia script into a sysimage. Sysimages can be used to speed up Julia startup times by precompiling modules. ```julia # Linking a sysimage img = ImageRecipe(output_type = "--output-sysimage", file = "src/image.jl") compile_products(img) link = LinkRecipe( image_recipe = img, outname = "build/custom.so", ) link_products(link) ``` -------------------------------- ### Library API: Compile, Link, and Bundle Products Source: https://github.com/julialang/juliac.jl/blob/main/README.md Use the JuliaC library API to define and execute compilation, linking, and bundling steps. This example demonstrates creating an executable bundle. ```julia using JuliaC img = ImageRecipe( output_type = "--output-exe", file = "test/AppProject", trim_mode = "safe", add_ccallables = false, verbose = true, ) link = LinkRecipe( image_recipe = img, outname = "build/app_test_exe", ) bun = BundleRecipe( link_recipe = link, output_dir = "build", # or `nothing` to skip bundling ) compile_products(img) link_products(link) bundle_products(bun) ``` -------------------------------- ### CPU Target Specification Examples Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/configuration.md Examples of CPU target strings for controlling compiler optimizations and feature usage. These strings define the architecture and specific CPU features to target. ```text "x86-64" ``` ```text "x86-64,avx2" ``` ```text "x86-64,avx2,fma" ``` ```text "x86-64,avx512f" ``` ```text "x86-64,avx2;x86-64" ``` ```text "arm64" ``` ```text "arm64,sve" ``` -------------------------------- ### Compile and Run a Minimal Julia Program Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/QUICKSTART.md This snippet shows how to define a simple Julia program, compile it into an executable using JuliaC, and then run the executable. Ensure you have JuliaC installed and accessible in your PATH. ```julia # hello.jl function @main(args::Vector{String}) println("Hello, world!") return 0 end # Compile julia -e "using JuliaC; JuliaC._main_cli([\"--output-exe\", \"hello\", \"hello.jl\"])" # Run ./hello ``` -------------------------------- ### Running JuliaC as a Pkg App Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/cli-and-main-entry.md Shows how to invoke the JuliaC CLI when it is installed as a Pkg application. Arguments after '--' are passed to JuliaC's main function. ```bash julia --project /path/to/juliac -e "using JuliaC; JuliaC.main(ARGS)" -- [args...] ``` -------------------------------- ### Display Juliac Usage Help Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/cli-and-main-entry.md This function prints the complete usage help text for the juliac command, including all available options and examples. It defaults to printing to standard output. ```julia function _print_usage(io::IO=stdout)::Nothing ``` -------------------------------- ### Verify C Compiler Installation Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/errors-and-diagnostics.md Checks if a C compiler (like GCC or Clang) is installed and accessible, which is necessary for C shim compilation. ```bash # Check C compiler is installed: gcc --version or clang --version ``` -------------------------------- ### Install JuliaC Package Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/QUICKSTART.md Add the JuliaC package to your Julia environment using the package manager. ```julia pkg> app add JuliaC ``` -------------------------------- ### JuliaC CLI: Shared Library with ABI Export Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/INDEX.md Command-line interface example for creating a shared library that exports its C API. Use `--compile-ccallable` and `--export-abi`. ```bash juliac --output-lib libmylib.so --compile-ccallable --export-abi abi.json src/lib ``` -------------------------------- ### Check Julia Binary Directory Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/QUICKSTART.md Verify the binary directory of your Julia installation. ```bash julia -e "using Base; println(Base.Sys.BINDIR)" ``` -------------------------------- ### Link Executable with Default Rpath Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-link-recipe.md Example of linking an executable using the default absolute rpath configuration. ```julia using JuliaC # Link an executable with default absolute rpath img = ImageRecipe(output_type = "--output-exe", file = "src/myapp.jl") compile_products(img) link = LinkRecipe( image_recipe = img, outname = "myapp", ) link_products(link) ``` -------------------------------- ### Configure Julia Options for ImageRecipe Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/QUICKSTART.md Example of setting Julia options within an ImageRecipe, such as disabling signals or setting thread count. ```julia ImageRecipe( jl_options = Dict( "handle-signals" => "no", # Disable signals (for libraries) "threads" => "4", # Set thread count ) ) ``` -------------------------------- ### Check Compiler and Julia Configuration Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/errors-and-diagnostics.md Verify the availability and paths of your compilers (gcc, clang) and check your Julia installation's binary directory. Also, inspect relevant environment variables like JULIA_CC and JULIA_CPU_TARGET. ```bash # See available compilers which gcc which clang # See Julia configuration julia -e "using Base; println(Base.Sys.BINDIR)" # Check environment echo $JULIA_CC echo $JULIA_CPU_TARGET ``` -------------------------------- ### Link Library with Custom Rpath and Linker Flags Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-link-recipe.md Example of linking a library with a custom relative rpath and additional linker flags. ```julia using JuliaC # Custom rpath and linker flags link = LinkRecipe( image_recipe = img, outname = "mylib.so", rpath = "../lib64", ld_flags = ["-Wl,--as-needed", "-Wl,-z,relro"], ) link_products(link) ``` -------------------------------- ### JuliaC CLI: Custom Julia Options Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/INDEX.md Command-line interface example for passing custom options to the Julia runtime, such as thread count. Use the `--jl-option` flag. ```bash juliac --output-exe app --jl-option threads=4 src/app ``` -------------------------------- ### Get All Configuration Flags Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieve a combined string of all compiler, linker, and library flags. The `framework` and `rpath` parameters control macOS framework paths and runtime library search paths, respectively. ```julia flags = JuliaConfig.allflags() # Returns all compiler, linker, and library flags combined # Example: "-std=gnu11 -I/path/to/julia/headers -fPIC -L/path/to/julia/lib -Wl,-rpath,... -ljulia" ``` -------------------------------- ### Get Linker Flags Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieve linker flags necessary for linking Julia libraries. The `framework` parameter adjusts paths for macOS framework installations. ```julia flags = JuliaConfig.ldflags() # Returns: "-L/path/to/julia/lib -Wl,--export-dynamic" (Linux) # Returns: "-F/path/to/julia/frameworks" (macOS with framework) ``` -------------------------------- ### Bundling with Default Settings Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-products.md Shows how to bundle products using a BundleRecipe with default settings, specifying only the link recipe and output directory. ```julia # Bundle with default settings bun = BundleRecipe( link_recipe = link, output_dir = "releases/v1.0", ) bundle_products(bun) ``` -------------------------------- ### Get C Compiler Flags Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieve C compiler flags for building C code that interfaces with Julia's C API. Use `framework=true` for macOS framework-based Julia installations. ```julia using JuliaC # Get C compiler flags flags = JuliaConfig.cflags() # Returns: "-std=gnu11 -I/path/to/julia/headers -fPIC" # With macOS framework (if applicable) flags = JuliaConfig.cflags(framework=true) # Returns: "-std=gnu11 -F/path/to/julia/frameworks -fPIC" ``` -------------------------------- ### Create and Compile Bundle Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-recipe.md Use `ImageRecipe` to create a complete bundle with default settings and then compile the products. This is the initial step before linking. ```julia using JuliaC # Create a complete bundle with default layout img = ImageRecipe(output_type = "--output-exe", file = "src/myapp.jl", verbose = true) compile_products(img) ``` -------------------------------- ### Build Option: Project Directory Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/configuration.md Specify the project directory to use for instantiation and precompilation. This can be a directory or a Project.toml file path. ```bash --project ``` -------------------------------- ### Complete Bundling Pipeline Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-products.md Demonstrates a complete pipeline for creating an executable with JuliaC, including image recipe, link recipe, and bundle recipe configurations. ```julia using JuliaC # Complete pipeline with bundling img = ImageRecipe( output_type = "--output-exe", file = "test/AppProject", trim_mode = "safe", verbose = true, ) link = LinkRecipe( image_recipe = img, outname = "myapp", rpath = "@bundle", # Use relative rpath for bundle ) bun = BundleRecipe( link_recipe = link, output_dir = "dist", libdir = "lib", ) compile_products(img) link_products(link) bundle_products(bun) ``` -------------------------------- ### Correct Order for Product Compilation and Bundling Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/errors-and-diagnostics.md Ensures that product compilation and instantiation occur before bundling. This is crucial to avoid 'project was not copied/instantiated' errors. ```julia compile_products(img) # Must be called first link_products(link) # Sets instantiated_project bundle_products(bun) # Uses instantiated_project ``` -------------------------------- ### Bundling with Privatized Libjulia (Unix Only) Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-products.md Demonstrates bundling with the `privatize` option enabled, which is specific to Unix-like systems. On Windows, this logs a warning and skips privatization. ```julia # Bundle with privatized libjulia (Unix only) bun = BundleRecipe( link_recipe = link, output_dir = "dist", privatize = true, ) bundle_products(bun) ``` -------------------------------- ### Information Option: Help Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/configuration.md Print the usage help message for the JuliaC command-line interface. ```bash -h ``` ```bash --help ``` -------------------------------- ### Link Library with Bundle-Relative Rpath Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-link-recipe.md Example of linking a library using the '@bundle' rpath for portable distribution. ```julia using JuliaC # Link a library with bundle-relative rpath for distribution img = ImageRecipe(output_type = "--output-lib", file = "src/mylib") compile_products(img) link = LinkRecipe( image_recipe = img, outname = "build/libmylib.so", rpath = "@bundle", ) link_products(link) ``` -------------------------------- ### JuliaC CLI Error Message Example Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/cli-and-main-entry.md Illustrates the standard error message format when JuliaC encounters a failure during execution. ```text ERROR: Failed to compile src/myapp.jl ``` -------------------------------- ### Direct Library Usage in Julia Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/architecture-and-modules.md Demonstrates how to use JuliaC as a library for direct recipe construction and compilation. ```julia using JuliaC # Direct recipe construction recipe = ImageRecipe(...) compile_products(recipe) # Inspect intermediate results println(recipe.img_path) # Location of compiled object ``` -------------------------------- ### Get macOS Framework Directory Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieves the macOS framework directory for Julia. This is only relevant on macOS when Julia is built as a framework. ```julia function frameworkDir()::String ``` ```julia # macOS only fwdir = JuliaConfig.frameworkDir() # Returns: "/Library/Frameworks/Julia.framework" ``` -------------------------------- ### Build a Smaller Bundle with Trimming Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/00-START-HERE.txt Use this command to build an executable with code trimming enabled for a smaller binary size. Specify the output file name, trim mode, and source directory. ```bash juliac --output-exe app --trim=safe --bundle dist src/app ``` -------------------------------- ### Bundle Products with Default Layout Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-recipe.md Use `BundleRecipe` to bundle the linked products into a specified output directory using the default directory layout. ```julia bun = BundleRecipe( link_recipe = link, output_dir = "dist", ) bundle_products(bun) ``` -------------------------------- ### Display Juliac Version Information Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/cli-and-main-entry.md This function prints the version information for both juliac and the underlying Julia installation. It defaults to printing to standard output. ```julia function _print_version(io::IO=stdout)::Nothing ``` -------------------------------- ### Manually Test Package Instantiation and Precompilation Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/errors-and-diagnostics.md Manually runs Pkg.instantiate() and Pkg.precompile() within a project directory to diagnose and resolve dependency or precompilation issues. ```julia # Test manually cd("your_project") using Pkg Pkg.instantiate() # See detailed error Pkg.precompile() # See detailed error ``` -------------------------------- ### Configure Compilation, Linking, and Bundling with Recipes Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/README.md This snippet demonstrates how to define and use ImageRecipe, LinkRecipe, and BundleRecipe to configure the compilation, linking, and bundling stages of a Julia project. Use this to set up the build process for executables, libraries, or portable bundles. ```julia img = ImageRecipe(output_type = "--output-exe", file = "src/app") link = LinkRecipe(image_recipe = img, outname = "myapp") bun = BundleRecipe(link_recipe = link, output_dir = "dist") compile_products(img) link_products(link) bundle_products(bun) ``` -------------------------------- ### Windows Platform Layout Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-products.md Illustrates the typical directory structure for bundled products on Windows systems. ```text output_dir/ └── bin/ ├── myexe.exe (executable) ├── libjulia.dll ├── libjulia-internal.dll └── ... ``` -------------------------------- ### Get Julia Private Library Directory Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieves the path to Julia's private library directory. These are internal libraries not part of the public API. ```julia function private_libDir()::String ``` ```julia privdir = JuliaConfig.private_libDir() # Returns: "/usr/lib/julia/private" ``` -------------------------------- ### Get Julia Library Directory Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieves the path to Julia's public library directory. Use this to locate shared libraries required by Julia. ```julia function libDir()::String ``` ```julia libdir = JuliaConfig.libDir() # Returns: "/usr/lib/julia" or equivalent on current system ``` -------------------------------- ### Get JuliaC Compiler and Linker Flags Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieve necessary flags for compiling C code against Julia. These flags are essential for ensuring compatibility and proper linking. ```julia using JuliaC # Get all necessary flags for compiling C code against Julia cflags = JuliaC.JuliaConfig.cflags() ldflags = JuliaC.JuliaConfig.ldflags() ldlibs = JuliaC.JuliaConfig.ldlibs(rpath=true) # Use in a custom build system all_flags = "$cflags $ldflags $ldlibs" println("Compile C with: gcc -c myfile.c $all_flags") println("Link executable: gcc myfile.o $all_flags -o myexe") # Or use with ImageRecipe recipe = ImageRecipe( output_type = "--output-exe", file = "src/app", c_sources = ["src/native.c"], cflags = Base.shell_split(cflags), ) ``` -------------------------------- ### Configure Smaller Binary with Trimming using Library API Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/QUICKSTART.md Configure an executable recipe with trimming enabled for a smaller binary size. ```julia img = ImageRecipe( output_type = "--output-exe", file = "src/app", trim_mode = "safe", julia_args = ["--experimental"], ) ``` -------------------------------- ### Get Detailed Error Output for Compilation Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/errors-and-diagnostics.md Uses the --verbose flag with juliac to obtain detailed error output during compilation, aiding in diagnosing compiler issues. ```bash # Get detailed error output juliac --output-exe myapp --verbose src/app # Test code directly julia --eval "include(\"src/app.jl\")" ``` -------------------------------- ### Unix Platform Layout Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-products.md Illustrates the typical directory structure for bundled products on Unix-like systems (Linux, macOS). ```text output_dir/ ├── bin/ │ └── myexe (executable or symlink) └── lib/ (or custom libdir) ├── julia/ │ ├── libjulia.so (or .dylib on macOS) │ ├── libjulia-internal.so │ └── ... └── libmylib.so (if building a library) ``` -------------------------------- ### Get Julia Include Directory Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieves the path to the directory containing Julia's C API headers. Use this when compiling C code that interfaces with Julia. ```julia function includeDir()::String ``` ```julia incdir = JuliaConfig.includeDir() # Returns: "/usr/include/julia" ``` -------------------------------- ### JuliaC CLI Options: Development Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/QUICKSTART.md Utilize development-focused options for JuliaC, such as verbose output or help information. ```bash # Development --verbose # Show all commands --quiet # Suppress output --version # Show versions --help # Show help ``` -------------------------------- ### bundle_products() Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/INDEX.md Executes the bundling process based on a BundleRecipe, packaging a linked artifact and its dependencies into a relocatable directory. ```APIDOC ## bundle_products() ### Description Executes the bundling process using a `BundleRecipe` and the linked output from `link_products()`. ### Input - `BundleRecipe` - The bundling configuration, which includes a linked `LinkRecipe`. ### Output - Relocatable directory containing the artifact and all its dependencies. ### Performs - Library copying - Directory reorganization - Optional privatization of symbols. ``` -------------------------------- ### Complete Library Compilation and Patching Workflow Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/patch-version-reference.md This snippet demonstrates the full process of compiling a library, linking it, and then creating a new versioned shared library using the `PatchVersion.patch_version` function. Ensure you have the necessary `JuliaC` and `JuliaC.PatchVersion` modules imported. ```julia using JuliaC using JuliaC.PatchVersion # Compile a library img = ImageRecipe( output_type = "--output-lib", file = "src/mylib", verbose = true, ) compile_products(img) # Link it link = LinkRecipe( image_recipe = img, outname = "build/libmylib.so.1.0", ) link_products(link) # Create version 2.0 variant PatchVersion.patch_version( "build/libmylib.so.1.0", "1.0", "2.0", "build/libmylib.so.2.0" ) # Now you have both: # - build/libmylib.so.1.0 (original) # - build/libmylib.so.2.0 (patched version) ``` -------------------------------- ### Compile and Link Shared Library with Custom Rpath Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-link-products.md This example demonstrates linking a Julia script into a shared library with a custom runtime path (`rpath`). The `rpath` is set to `@bundle` for bundling with the application. ```julia # Linking with custom rpath img = ImageRecipe(output_type = "--output-lib", file = "src/mylib") compile_products(img) link = LinkRecipe( image_recipe = img, outname = "build/libmylib.so", rpath = "@bundle", ) link_products(link) ``` -------------------------------- ### Link Products Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-recipe.md Use `LinkRecipe` to link the compiled products, specifying the output name. This prepares the artifacts for bundling. ```julia link = LinkRecipe(image_recipe = img, outname = "myapp") link_products(link) ``` -------------------------------- ### Get CPU Architecture Compiler Flags Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieves CPU architecture-specific compiler flags. Returns an empty string on 64-bit systems without special flags, or specific flags for 32-bit x86. ```julia function march_flags()::String ``` ```julia flags = JuliaConfig.march_flags() # Returns: "" (64-bit) or "-m32 -march=pentium4" (32-bit x86) ``` -------------------------------- ### Bundle Products with Custom Library Directory Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-recipe.md Customize the bundling process by specifying a custom directory for libraries using the `libdir` option in `BundleRecipe`. ```julia bun = BundleRecipe( link_recipe = link, output_dir = "dist", libdir = "lib64", ) bundle_products(bun) ``` -------------------------------- ### Specify Output File Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/errors-and-diagnostics.md Ensure that at least one output flag (--output-exe, --output-lib, --output-sysimage, --output-o, or --output-bc) is provided when compiling. -------------------------------- ### Get Linker Libraries Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/julia-config-reference.md Retrieve linker library flags for linking Julia libraries. Control runtime library search paths with the `rpath` parameter and use `framework=true` for macOS framework linking. ```julia # With rpath (default) flags = JuliaConfig.ldlibs() # Returns: "-L/path/to/julia/lib/private -Wl,-rpath,/path/to/julia/lib -ljulia" (Unix) # Without rpath (for static linking) flags = JuliaConfig.ldlibs(rpath=false) # Returns: "-L/path/to/julia/lib/private" (Unix) # macOS framework flags = JuliaConfig.ldlibs(framework=true) # Returns: "-framework Julia" ``` -------------------------------- ### Build an Executable Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/00-START-HERE.txt Use this command to build a native executable from Julia source files. Specify the output file name and the source directory. ```bash juliac --output-exe myapp --bundle dist src/app ``` -------------------------------- ### _main_cli Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/cli-and-main-entry.md Orchestrates the compilation, linking, and bundling pipeline. It handles help and version checks, argument parsing, and pipeline execution. ```APIDOC ## _main_cli ### Description Orchestrates the compilation, linking, and bundling pipeline. ### Signature ```julia function _main_cli(args::Vector{String}; io::IO=stdout)::Nothing ``` ### Parameters #### Arguments - **args** (Vector{String}) - Required - Command-line arguments - **io** (IO) - Optional - Output stream for help/version information (default: `stdout`) ### Returns - Nothing ### Description Main orchestration function that: 1. Checks for help (`-h`, `--help`) and displays usage 2. Checks for version (`--version`) and displays version info 3. Parses CLI arguments into recipes 4. Executes the pipeline: compile → link → bundle ### Example ```julia using JuliaC # Interactive usage JuliaC._main_cli([ "--output-exe", "myapp", "--bundle", "dist", "--trim=safe", "test/AppProject" ]) # Help JuliaC._main_cli(["-h"]) # Version JuliaC._main_cli(["--version"]) ``` ``` -------------------------------- ### Set Custom Compiler Path for Juliac Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/errors-and-diagnostics.md If Juliac cannot find a suitable C compiler, you can explicitly set the path to the desired compiler using the `JULIA_CC` environment variable. This is useful when a compiler is installed but not in the system's default PATH. ```bash export JULIA_CC=/usr/bin/gcc-12 juliac --output-exe myapp src/app ``` -------------------------------- ### @main Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/cli-and-main-entry.md The Julia app entry point that processes command-line arguments and runs the build pipeline. It is the top-level function invoked when running `juliac` from the command line. ```APIDOC ## @main ### Description The Julia app entry point that processes command-line arguments and runs the build pipeline. ### Signature ```julia function (@main)(ARGS::Vector{String}) ``` ### Parameters #### Arguments - **ARGS** (Vector{String}) - Required - Command-line arguments passed by Julia's app system ### Returns - Nothing (exit code is implicit) ### Description This is the top-level entry point for the `juliac` app. It's invoked automatically when running `juliac` from the command line or when using `julia --project -e "using JuliaC; JuliaC.main(ARGS)" -- `. ``` -------------------------------- ### Compile Basic Executable with ImageRecipe Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-image-recipe.md Use ImageRecipe to create a basic executable from a Julia source file. Set output_type to "--output-exe" and specify the source file. ```julia using JuliaC # Basic executable compilation img = ImageRecipe( output_type = "--output-exe", file = "src/myapp.jl", verbose = true, ) compile_products(img) ``` -------------------------------- ### Build Executable using CLI Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/QUICKSTART.md Use the JuliaC CLI to build an executable application from a Julia source file. ```bash juliac --output-exe myapp --bundle dist src/MyApp.jl ``` -------------------------------- ### JuliaC Main Entry Point Precompilation Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/cli-and-main-entry.md Ensures the main entry point of JuliaC is precompiled to reduce CLI startup time. This directive is included within the module. ```julia precompile(main, (Vector{String},)) ``` -------------------------------- ### Create Bundled Distribution with JuliaC Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/INDEX.md This workflow creates a smaller, self-contained executable bundle. It includes options for trimming and custom Julia arguments. Ensure JuliaC is imported. ```julia using JuliaC img = ImageRecipe( output_type = "--output-exe", file = "src/app", trim_mode = "safe", # Smaller bundle julia_args = ["--experimental"], ) link = LinkRecipe(image_recipe = img, outname = "myapp", rpath = "@bundle") bun = BundleRecipe(link_recipe = link, output_dir = "dist") compile_products(img) link_products(link) bundle_products(bun) ``` -------------------------------- ### Skip Bundling Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/api-reference-bundle-recipe.md To skip the bundling process entirely, set `output_dir` to `nothing` in `BundleRecipe`. Calling `bundle_products` in this state will be a no-op. ```julia bun = BundleRecipe( link_recipe = link, output_dir = nothing, # No bundling ) bundle_products(bun) # This is a no-op ``` -------------------------------- ### Create Version-Compatible Symlinks Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/patch-version-reference.md Create version-compatible copies or symlinks for libraries. This is useful for maintaining compatibility across different library versions. ```julia using JuliaC.PatchVersion # Build library for version 1.0 # ... # Create a version 2.0-compatible copy patch_version("mylib.so.1.0", "1.0", "2.0", "mylib.so.2.0") ``` -------------------------------- ### Bash: Specify Project Path Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/cli-and-main-entry.md Specifies the project path for the build. Defaults to the active project if not provided. Can be a directory or a Project.toml file. ```bash juliac --output-exe app --project src/myapp test/app.jl ``` ```bash juliac --output-lib lib.so --project=/custom/project src/entry.jl ``` -------------------------------- ### Build Option: Bundle Libraries Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/configuration.md Bundle Julia libraries and artifacts into a specified directory. If no directory is given, it defaults to the directory of the output artifact. ```bash --bundle [] ``` -------------------------------- ### Configure C Compiler and CPU Target Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/QUICKSTART.md Set environment variables to specify the C compiler and CPU target for JuliaC builds. ```bash # Set C compiler export JULIA_CC=/usr/bin/gcc-12 # Set CPU target export JULIA_CPU_TARGET=x86-64,avx2 ``` -------------------------------- ### Create Basic Executable with JuliaC Source: https://github.com/julialang/juliac.jl/blob/main/_autodocs/INDEX.md Use this to create a standalone executable from your Julia application. Ensure JuliaC is imported. ```julia using JuliaC img = ImageRecipe(output_type = "--output-exe", file = "src/app") link = LinkRecipe(image_recipe = img, outname = "myapp") compile_products(img) link_products(link) ```