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

Standard library documentation #1

Merged
merged 26 commits into from
Apr 26, 2020
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f5f9757
Standard library empty pages
BenjaminNavarro Apr 11, 2020
a278feb
std/io doc update
BenjaminNavarro Apr 11, 2020
13a3a0b
Minors fixes to std/io
BenjaminNavarro Apr 12, 2020
2731052
str module documentation
BenjaminNavarro Apr 12, 2020
2f71cce
Fixes in std/str
BenjaminNavarro Apr 12, 2020
cf60f71
Fixes in std/str
BenjaminNavarro Apr 13, 2020
5c7aa1c
std/vec doc
BenjaminNavarro Apr 13, 2020
885b202
Minor fixes
BenjaminNavarro Apr 13, 2020
46db3bf
std/lang doc
BenjaminNavarro Apr 14, 2020
adb4199
Fix std/vec member functions ordering
BenjaminNavarro Apr 14, 2020
e1d2a5a
std/map doc
BenjaminNavarro Apr 14, 2020
fd7766b
Move all imports in the header for clearer examples
BenjaminNavarro Apr 15, 2020
cf1e023
std/fs doc
BenjaminNavarro Apr 15, 2020
51954d1
Minor fixes to std/fs
BenjaminNavarro Apr 16, 2020
e298454
std.core doc outline
BenjaminNavarro Apr 21, 2020
caecfc7
Move part of std.str to std.core
BenjaminNavarro Apr 21, 2020
8a190ee
Minor fix in std/fs
BenjaminNavarro Apr 21, 2020
501f48b
std/os doc
BenjaminNavarro Apr 21, 2020
ebbae33
Add new sections
BenjaminNavarro Apr 21, 2020
7bf552b
Fixing typos
BenjaminNavarro Apr 22, 2020
0ae17fd
std/runtime doc
BenjaminNavarro Apr 22, 2020
c47681f
std/ptr doc
BenjaminNavarro Apr 22, 2020
c7cf6be
Merging std/runtime with std/sys
BenjaminNavarro Apr 22, 2020
76ee8a4
Addressing PR comments
BenjaminNavarro Apr 24, 2020
4b2bbef
std/builder doc
BenjaminNavarro Apr 25, 2020
06be0a0
Addressing PR comments
BenjaminNavarro Apr 25, 2020
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
174 changes: 174 additions & 0 deletions src/std/10-std-builder.md
Original file line number Diff line number Diff line change
@@ -1 +1,175 @@
# Builder

The **builder** module defines a `builder` type that allows to build and install C++ modules to be used with Feral
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

builder_t type

install C++ modules install external modules
(because it's not C++ exclusive, it can install Feral only modules too)


A guide on how to write and build modules for Feral can be read [here](https://levelup.gitconnected.com/writing-c-modules-for-feral-391c30ac7739).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


All the given examples assume that the **builder** module was imported using:
```
let builder = import('std/builder');
let io = import('std/io');
let sys = import('std/sys');
```

## Functions
- [new](#new)

## `builder` Member Functions
- [make_dll](#make_dll)
- [add_comp_opts](#add_comp_opts)
- [add_inc](#add_inc)
- [add_lib](#add_lib)
- [add_src](#add_src)
- [perform](#perform)

### new
```
builder.new() -> builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> builder -> builder_t

```
Creates a new builder with default build settings

Example:
```
let build = builder.new();
io.println(build);
```

Possible output:
```
typeid<14>{linker_flags: , lib_flags: -lferalvm -lgmpxx -lgmp -lmpfr , lib_dirs: -L/usr/lib -L/usr/local/lib/feral , srcs: , ccache: /usr/bin/ccache , compiler: g++, is_dll: false, compiler_opts: -std=c++11 -O2 , inc_dirs: -I/usr/include }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in commit 50217df of Feral-Std, added typename for builder_t so now it will show builder_t instead of typeid<14>

```

### make_dll
```
builder.make_dll() -> builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> builder -> builder_t

```
Indicates that the module should be built as a dynamic library instead of an executable program

Example:
```
let build = builder.new();
io.println("Is DLL? ", build.is_dll, ". Compiler options: ", build.compiler_opts);
build.make_dll();
io.println("Is DLL? ", build.is_dll, ". Compiler options: ", build.compiler_opts);
```

Possible output:
```
Is DLL? false. Compiler options: -std=c++11 -O2
Is DLL? true. Compiler options: -std=c++11 -O2 -shared -fPIC -rdynamic -Wl,-rpath,/home/feral/.feral/lib
```

### add_comp_opts
```
builder.add_comp_opts(opt: string) -> builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> builder -> builder_t

```
Adds `opt` to the list of options passed to the compiler

Example:
```
let build = builder.new();
io.println("Compiler options: ", build.compiler_opts);
build.add_comp_opts('-g');
io.println("Compiler options: ", build.compiler_opts);
```

Possible output:
```
Compiler options: -std=c++11 -O2
Compiler options: -std=c++11 -O2 -g
```

### add_inc
```
builder.add_inc(inc_dir: string) -> builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> builder -> builder_t

```
Adds `inc_dir` to the list of include directories passed to the compiler

Example:
```
let build = builder.new();
io.println("Include directories: ", build.inc_dirs);
build.add_inc('-I/usr/local/include');
io.println("Include directories: ", build.inc_dirs);
```

Possible output:
```
Include directories: -I/usr/include
Include directories: -I/usr/include -I/usr/local/include
```

### add_lib
```
builder.add_lib(lib_flag : string, lib_dir = '' : string) -> builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> builder -> builder_t

```
Adds `lib_flag` and `lib_dir` to the list of libraries and library directories passed to the compiler

Example:
```
let build = builder.new();
io.println("Libraries and directories \n\t", build.lib_flags, "\n\t", build.lib_dirs);
build.add_lib('-lcurl', '-L/usr/local/lib');
io.println("Libraries and directories \n\t", build.lib_flags, "\n\t", build.lib_dirs);
```

Possible output:
```
Libraries and directories
-lferalvm -lgmpxx -lgmp -lmpfr
-L/usr/lib -L/usr/local/lib/feral
Libraries and directories
-lferalvm -lgmpxx -lgmp -lmpfr -lcurl
-L/usr/lib -L/usr/local/lib/feral -L/usr/local/lib
```

### add_src
```
builder.add_src(src: string) -> builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> builder -> builder_t

```
Adds `src` to the list of source files passed to the compiler

Example:
```
let build = builder.new();
io.println("Source files: ", build.srcs);
build.add_src('src/hello.cpp');
io.println("Source files: ", build.srcs);
```

Possible output:
```
Source files:
Source files: src/hello.cpp
```

### perform
```
builder.perform(output_file: string, .kw_args) -> builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns integer, not builder_t
(0 = success, fail otherwise)

```
Builds the module and produces the `output_file` binary output. The possible keyword arguments are:
- `src`: Additional source files to build. Default if empty
- `inc`: Include files location. Default is `include`
- `lib`: Library files location. Default is `build`
- `bin`: Executable files location. Default is `bin`

The build is also influenced by the following command line arguments:
- `dry` : Dry run
- `install` : Install the module in addition of building it

Example:
```
let build = builder.new().make_dll();
build.add_src('src/learn.cpp');
sys.exit(build.perform('learn'));
```

Possible output:
```
$ feral install
Building ...
=> build/libferallearn.so
Installing ...
=> build/* -> /home/feral/.feral/lib/ ...
Installation successful!
```