Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for Flags and Link annotations #7665

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/annotations.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,45 @@
# ```
annotation Deprecated
end

# An enum can be marked with `@[Flags]`. This changes the default values.
# The first constant's value is 1, and successive constants are multiplied by 2.
#
# ```
# @[Flags]
# enum IOMode
# Read # 1
# Write # 2
# Async # 4
# end
#
# (IOMode::Write | IOMode::Async).value # => 6
# puts IOMode::Write | IOMode::Async # => Write | Async
# ```
annotation Flags
end

# A `lib` can be marked with `@[Link(lib : String, ldflags : String, static : Bool, framework : String)]`
# to declare the library that should be linked when compiling the program.
#
# At least one of the *lib*, *ldflags*, *framework* arguments needs to be specified.
#
# `@[Link(ldflags: "-lpcre")]` will pass `-lpcre` straight to the linker.
#
# `@[Link("pcre")]` will lookup for a shared library.
# 1. will lookup `pcre` using `pkg-config`, if not found
# 2. will pass `-lpcre` to the linker.
#
# `@[Link("pcre", static: true)]` will favor static libraries over shared libraries.
# 1. will lookup `libpcre.a` in `CRYSTAL_LIBRARY_PATH`, if not found
# 2. will lookup `pcre` using `pkg-config --static`, if not found,
# 3. will lookup `libpcre.a` in `/usr/lib`, `/usr/local/lib`
#
# `@[Link(framework: "Cocoa")]` will pass `-framework Cocoa` to the linker.
#
# When an `-l` option is passed to the linker, it will lookup the libraries in
# paths passed with the `-L` option. `CRYSTAL_LIBRARY_PATH`, `/usr/lib`,
# and `/usr/local/lib` are added by default. Custom paths can be passed
# using `ldflags`: `@[Link(ldflags: "-Lvendor/bin")]`.
annotation Link
end