-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support library source file archives
- Loading branch information
1 parent
62e9d70
commit 23284e6
Showing
11 changed files
with
603 additions
and
22 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,97 @@ | ||
# Support Source Archive Files | ||
|
||
This is a compiler feature, not a D language feature. | ||
|
||
Similar to how libraries of object files are made available to the linker, | ||
this adds source archive file support to the compiler. Any package (and all its | ||
sub-files) can become a source archive file. The source archive file is then | ||
supplied to the compiler rather than a directory with lots of files in it. | ||
|
||
This means, for example, that all of Phobos can be distributed as a single | ||
file, std.sar. (The .sar extension stands for "source archive".) If std.sar | ||
is in a path along the import path list supplied to the compiler, the | ||
compiler will prefer std.sar to looking through the std directory tree for the | ||
sub-modules. The std directory wouldn't even need to exist. | ||
|
||
The file format of the .sar file is very similar to that of object file libraries | ||
and various other schemes. It does not adhere to those other schemes due to their | ||
variances from platform to platform, all the code needed to support things that | ||
are unneeded for .sar files, and special consideration for D's needs. The format | ||
is meant to be friendly for memory-mapped file access, and does not have alignhment | ||
issues. | ||
|
||
A .sar file consists of the following sections: | ||
|
||
1. a header, to identify it as a .sar file with a magic number and a version | ||
|
||
2. a table of contents, one entry per source file. The entries consist of | ||
an offset/length to the filename string, and an offset/length to the file | ||
contents | ||
|
||
3. the filename strings, each string has a terminating 0 | ||
|
||
4. the file contents, each file has four 0 bytes appended, as the lexer wants | ||
that as a sentinel | ||
|
||
5. the integers in the format are little-endian | ||
|
||
To create a .sar file, such as one for Phobos' std: | ||
|
||
dmd -sar=/home/duser/dmd/src/phobos/std | ||
|
||
and the file: | ||
|
||
/home/duser/dmd/src/phobos/std.sar | ||
|
||
will be created and filled with all sub-files with one of the extensions ".di", ".d", | ||
".c", or ".i". The filenames in the .sar file will include the path prefix | ||
specified in the -sar switch. This means the .sar file cannot be successfully moved | ||
to another location. | ||
|
||
For Phobos, std.sar is approximately 11 megabytes in size. | ||
|
||
To use the std.sar file, nothing needs to be changed in the user's build system. | ||
dmd will automatically prefer using any .sar file it finds. To disable using | ||
.sar files, which would be necessary when doing development of the source files, | ||
select one of the following: | ||
|
||
1. delete the .sar file | ||
|
||
2. use the -sar=off compiler switch. -sar=on turns it on, and is the default | ||
setting | ||
|
||
Trying out .sar with simple programs like hello world yield a negligible difference | ||
in compile speed. It's unlikely a larger program would show any particular trend | ||
in performance. | ||
|
||
A standalone archiver program can be easily created from the implementation in DMD. | ||
|
||
## Rationale | ||
|
||
1. All the source files in a project or library can be represented as a single file, | ||
making it easy to deal with. | ||
|
||
2. To compile all the source files at once with DMD, the command line can get | ||
extremely long, and certainly unwieldy. With .sar files, you may not even need | ||
a makefile or builder, just: | ||
|
||
dmd project.sar | ||
|
||
3. In Phobos (and most code), the tendency is to lump a lot of only marginally related | ||
functions into one file. This is likely because of the inconvenience of multiple files. | ||
In std.algorithm, for example, the individual algorithms could be placed into multiple | ||
files, since they don't refer to each other. This could also help the people who | ||
don't want the automatic "friend" status of declarations within a single module. | ||
.sar files can make much more granular modules more attractive. | ||
|
||
4. A directory in a project can be anything. But multiple .sar files in a project means | ||
that's where the code is. Multiple versions of the project can exist in the same directory | ||
by using .sar files with different names. | ||
|
||
5. Experiments with small programs (hello world) show a negligible change in compile | ||
speed. Much larger programs may show significant compile speed increases with .sar | ||
files, simply because there are fewer file operations. For slow file systems, such as | ||
SD cards, or network file systems, the speedup could be substantial. | ||
|
||
None of these make it a slam-dunk, after all, no other compiler does this that I'm | ||
aware of. Even so, some surprising uses can be expected of .sar files. |
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
Oops, something went wrong.