#swift #compile-time #macro #string-literal #config-file #include-str #precompiler

nightly app swift-precompiler

A precompiler for Swift that allows you to use additional macros, include files, and more

6 releases

0.1.5 Mar 9, 2024
0.1.4 Mar 9, 2024
0.1.2 Jan 13, 2024

#81 in Programming languages

Download history 11/week @ 2024-01-12 3/week @ 2024-02-16 2/week @ 2024-02-23 162/week @ 2024-03-01 249/week @ 2024-03-08 14/week @ 2024-03-15 1/week @ 2024-03-22 37/week @ 2024-03-29 68/week @ 2024-04-05

127 downloads per month

MIT license

20KB
267 lines

Swift Precompiler

⚡ A fast, lightweight precompiler for Swift

Features

  • Add Rust's includeStr! like functionality to Swift with the precompileIncludeStr function

Installation

Cargo:

cargo install swift-precompiler

Configuration

Run swift-precompiler init to initialise a config file swift-precompiled.toml with the default values

Available options:

  • dirs - An array of directories to search for Swift source files that require precompilation
  • path_aliases - A dictionary of path aliases to use in precompile calls

Example:

dirs = ["Cider/", "CiderPlaybackAgent/"]

[path_aliases]
# "@" as a path alias refers to the current working directory in most cases
"@" = "./"

Usage

Including a file as a string literal at compile time:

let javaScript = precompileIncludeStr("path/to/file.js")

Include a file as a Data at compile time:

let image = precompileIncludeData("path/to/image.png")

Run swift-precompiler to precompile all Swift files in the directories specified in the config file

swift-precompiler precompile

You should add Precompiled.swift to your .gitignore

Swift Precompiler encodes your strings with Base64, you can add swift-extras-base64 to your project using SPM to enable faster Base64 decode.

Dependencies

~4–15MB
~167K SLoC