-
-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement pragma compile on import bugzilla #24869
- Loading branch information
Showing
7 changed files
with
73 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
A new pragma is added that will compile a module on import. | ||
|
||
The pragma ``compileOnImport``, will convert an imported module into one that will be compiled into your binary. | ||
|
||
This is the same behavior as the ``-i`` switch, except it is a pragma in a module. | ||
|
||
A library module: | ||
|
||
```d | ||
module mylib; | ||
pragma(compileOnImport); | ||
|
||
void callMe() { | ||
import std.stdio; | ||
writeln("Hello!"); | ||
} | ||
``` | ||
|
||
The user module: | ||
|
||
```d | ||
module theuser; | ||
import mylib; | ||
|
||
void main() { | ||
callMe(); // Hello! | ||
} | ||
``` | ||
|
||
Compile with ``dmd -I. theuser.d`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
REQUIRED_ARGS: -Irunnable/imports | ||
*/ | ||
module compileonimport; | ||
import compileonimportlib; | ||
|
||
void main() { | ||
bool v = runMe(); | ||
assert(v); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module compileonimportlib; | ||
|
||
pragma(compileOnImport); | ||
|
||
bool runMe() { | ||
return true; | ||
} |