Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 14 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ resolver = "2"
members = [
"packages/cli",
"packages/lib",
"packages/lib/macros",
"packages/test-mod"
]

[workspace.dependencies]
Expand Down
3 changes: 3 additions & 0 deletions Lisensor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
"packages/lib/**/*.h" = "GPL-3.0-or-later"
"packages/lib/src/megaton/*.s" = "GPL-3.0-or-later"
"packages/lib/src/nximpl/*.s" = "GPL-3.0-or-later"
"packages/test-mod/**/*.cpp" = "GPL-3.0-or-later"
"packages/test-mod/**/*.h" = "GPL-3.0-or-later"

# Rust files
"packages/lib/**/*.rs" = "GPL-3.0-or-later"
"packages/cli/**/*.rs" = "MIT"
"packages/test-mod/**/*.rs" = "GPL-3.0-or-later"

# Unmodified files
# ["libnx Authors"]
Expand Down
10 changes: 5 additions & 5 deletions packages/docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
---
- [Installation](./install.md)
- [Tutorial](./tutorial/index.md)
- [Create Project]()
- [Incremental Build]()
- [Project Config]()
- [Build Flags]()
- [Create Project](./tutorial/create_project.md)
- [Incremental Build](./tutorial/incremental_build.md)
- [Build Flags](./tutorial/build_flags.md)
- [Profiles](./tutorial/profiles.md)
- [Check]()
- [Check](./tutorial/check.md)
- [Test Mod](./tutorial/test_mod.md)
- [C++/Rust APIs]()
- [Defines]()
- [Module]()
Expand Down
102 changes: 102 additions & 0 deletions packages/docs/src/tutorial/build_flags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Build Flags

Megaton uses a preset list of flags for the build toolchain both on the rust and
C/C++ sides. These flags should handle targeting the switch architecture and
platform. Certain optomizations are also enabled and certain features are diabled.
It is recommended to use all of the default flags since Megaton has not been tested
with any of the build flags disabled. However, you may add flags to certain parts
of the build pipeline, e.g., to add `-D` define statements or enable certain behavior
for your target game. These flags are all set in the `build.flags` section of the
Megaton config file. Certain command line flags, such as specifing a linker script,
are included implicitly and should be specified in the appropriate `build` config
option. See the full [build config](../reference/configuration/section_build.html)
documentation for a full description of how default flags are combined to form the
build commands.

```toml
[build.flags]
c = ["<default>", "-DMY_DEFINE=1"]
rust = ["<default>", "-Zub-checks=yes"]
cargo = ["<default>", "--features", "my-feature"]
```

There are 7 sections for flags to be added to, corresponding to different compilers
or parts of the build toolchain.

## Common
These flags are applied to all non-rust toolchain components, i.e. `cc`, `cxx`,
`as`, and `ld`.

#### Defaults
```
-march=armv8-a+crc+crypto
-mtune=cortex-a57
-mtp=soft
-fPIC
-fvisibility=hidden
-g
```

## C
These flags are passed to the C compiler when compiling C sources.

#### Defaults
```
-Wall
-Werror
-ffunction-sections
-fdata-sections
-O3
```

## CXX
These flags are passed to the C++ compiler when compiling C++ sources.

#### Defaults
```
-std=c++20
-fno-rtti
-fno-exceptions
-fno-asynchronous-unwind-tables
-fno-unwind-tables
```

## AS
These flags are passed to the assembler when compiling assembly sources.
There are currently no default flags used specifically for the assembler.
Note that the assembler tool used is actually gcc, so flags should be
formatted as gcc flags when used as an assembler.

## LD
These flags are passed to the linker when linking the ELF from all compiled
binary objects. Again, these are formatted as link flags for g++, not
for ld itself.

#### Defaults
```
-nostartfiles
-nodefaultlibs
-Wl,--shared
-Wl,--export-dynamic
-Wl,-z,nodynamic-undefined-weak
-Wl,--build-id=sha1
-Wl,--gc-sections
-Wl,--nx-module-name
```

## Rust
Flags passed to the rust compiler. Equivalent to the RUSTFLAGS environment variable.
Place flags here instead of Cargo.toml if you want them to be profile
controlled.

Currently no default rust flags.

## Cargo
Flags passed to cargo for building all rust code. The `+megaton` toolchain is
also implicitly included.

#### Defaults
```
--release
--target aarch64-unknown-hermit
```
28 changes: 28 additions & 0 deletions packages/docs/src/tutorial/check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Check

The Megaton check system allows an additional layer of verification following
linking. The check will ensure that there are no undefined symbols or disallowed
instructions.

The check will run anytime the ELF is relinked, and if the check fails, the
ELF will not be converted into an NSO, and the build will fail.

For a full guide on configuring the check step, see the
[configuration page](../reference/configuration/section_check.html)

## Symbol check

The built mod could cause crashes or unexpected behavior if certain symbols
remain undefined in the final binary. This is especially true while the tool
is in active development and certain standard library features are not yet
supported. Megaton will use `objdump` to obtain a list of dynamic symbols.
Dynamic symbols are only considered as defined if an included symbol file
specified in `check.symbols`. If check reports that a particular syscall
or system function is undefined, ensure that your mod SDK symbol file
contains that symbol.

## Disallowed instructions

During Megaton library development, it may be convenient to disable certain
instructions to prevent crashes due to assembly instructions that are known
to crash due to limitations in Megaton library support.
Loading
Loading