c3lang / c3c

Compiler for the C3 language

Home Page:https://c3-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Pragma link" attributes

lerno opened this issue · comments

In order to make it easier to do a minimum set of linking directives, an idea is to add a link attributes. Such an attribute can be put on a module section or a particular object:

module Foo @link("foo.a")

However, we run into the issue where the same module is linked in different ways. For instance, to link libc on Linux, typically "-lc" is used, whereas on MacOS it's "-lSystem"

Today* it's possible to do this workaround:

define @LinkLibC = @link("c") @if(env::LINUX);
define @LinkLibC = @link("System") @if(env::DARWIN);

module Foo @LinkLibC;

This is a very roundabout way however, and moves the definition away from the actual use.

We could imagine some more complex syntax for @link though:

// The least amount of extra syntax:
module libc @link(env::LINUX ? "c" : (env::DARWIN ? "System" : null));
// More declarative, but still custom:
module libc @link(env::LINUX = "c", env::DARWIN = "System");
// String based
module libc @link("linux:c", "macos:System");
// Multiple attributes
module libc @macos-link("System") @linux-link("c");
// Multiple attributes 2
module libc @link("System", env::DARWIN) @link("c", env::LINUX);

There's also the question of multiple links. Are those: @link("a") @link("b") or @link("a", "b") or @link("a;b")

* Maybe not actually possible, since module has restrictions on attributes.

Implemented.