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
8 changes: 8 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ package = "pistonite-cu"
version = "0.7.3"
# path = "../../../cu/packages/copper"

[workspace.dependencies.pm]
package = "pistonite-pm"
version = "0.2.6"

[workspace.dependencies]
static_assertions = "1.1.0"
hermit-abi = "0.5.2"
ignore = "0.4.25"
flate2 = "1.1.2"
tar = "0.4.44"
Expand Down
4 changes: 3 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tasks:
check-non-dkp:
- task: cli:check
- lisensor
- task: lib:check-rs
check-dkp:
- task: lib:configure
- task: lib:check-c
Expand All @@ -43,9 +44,10 @@ tasks:
build-non-dkp:
- task: cli:build
- task: docs:build
- task: lib:build-rs
build-dkp:
- task: lib:configure
- task: lib:build
- task: lib:build-c

license:
desc: check or fix license notices (-- -f to fix)
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ regex = "1.12.2"
cargo_metadata = "0.23.1"
semver = { version = "1.0.28", features = ["serde"] }

[build-dependencies.cu]
workspace = true
features = ["process"]

[build-dependencies]
cu = { workspace = true, features = ["process", "toml"] }
ignore.workspace = true
flate2.workspace = true
tar.workspace = true
Expand Down
53 changes: 53 additions & 0 deletions packages/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,59 @@ resolver = 2
members = [ "macros" ]
"##,
);
let mut cargo_toml = toml::parse::<toml::Table>(&cargo_toml)?;
// patch [dependencies] .workspace = true to be .version = <version spec in workspace>
let workspace = cu::fs::read_string(packages_path.parent_abs()?.join("Cargo.toml"))?;
let workspace = toml::parse::<toml::Table>(&workspace)?;

// collect deps to inherit
let mut workspace_dep_names = vec![];
let deps = cu::check!(
cargo_toml.get("dependencies").and_then(|x| x.as_table()),
"didn't find megaton lib dependencies or is not table"
)?;
for (dep_name, dep_data) in deps {
let Some(dep_data) = dep_data.as_table() else {
continue;
};
let is_workspace = dep_data
.get("workspace")
.and_then(|x| x.as_bool())
.unwrap_or(false);
if is_workspace {
workspace_dep_names.push(dep_name.clone());
}
}

// copy from workspace toml
let workspace_deps = cu::check!(
workspace
.get("workspace")
.and_then(|x| x.as_table())
.and_then(|x| x.get("dependencies"))
.and_then(|x| x.as_table()),
"didn't find workspace dependencies or is not table"
)?;
let mut new_workspace_deps = toml::Table::new();
for dep_name in workspace_dep_names {
let workspace_dep_data = cu::check!(
workspace_deps.get(&dep_name),
"did not find dependency '{dep_name}' in workspace"
)?;
if let Some(data) = workspace_dep_data.as_table() {
if data.get("path").is_some() {
cu::bail!("workspace dep cannot have path when packing library: {dep_name}");
}
}
new_workspace_deps.insert(dep_name, workspace_dep_data.clone());
}
// unwrap: we added it as string above
cargo_toml["workspace"]
.as_table_mut()
.unwrap()
.insert("dependencies".to_string(), new_workspace_deps.into());

let cargo_toml = toml::stringify_pretty(&cargo_toml)?;
let bytes = cargo_toml.as_bytes();
let mut header = tar::Header::new_gnu();
header.set_path("Cargo.toml")?;
Expand Down
5 changes: 5 additions & 0 deletions packages/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
name = "megaton"
version = "0.0.0"
edition = "2024"
license = "GPL-3.0-or-later"
description = "Megaton Library that works with the build tool. Automatically unpacked by the build tool" # for the library unpacked by build tool
publish = false

[dependencies]
static_assertions.workspace = true
hermit-abi.workspace = true
megaton-macros.path = "macros"
21 changes: 18 additions & 3 deletions packages/lib/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@ tasks:
cmds:
- cmake -G Ninja -B build -S .

build:
desc: Execute incremental build
build-c:
cmds:
- ninja -C build

build-rs:
cmds:
- cargo build

clean:
desc: Clean build directory
cmds:
- rm -rf build
- rm -rf build target

check:
- task: check-rs
- task: check-c

check-c:
cmds:
Expand All @@ -38,8 +45,16 @@ tasks:
HEADER: ^include/
ADD_CHECKS: >
-bugprone-easily-swappable-parameters

check-rs:
cmds:
- task: cargo:clippy-all
- task: cargo:fmt-check
fix:
cmds:
- task: ccpp:fmt-fix
vars:
SOURCE: src/megaton src/nximpl
- task: cargo:fmt-fix


31 changes: 31 additions & 0 deletions packages/lib/include/megaton/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 Megaton contributors

#pragma once
#include <megaton/attributes.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* Rust entry point, generated by megaton::main macro in Rust.
* Use megaton::rust_main instead of this function!!
*/
// NOLINTNEXTLINE(bugprone-reserved-identifier) FIXME
void __megaton_rs_main();

#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
namespace megaton {
/**
* Call the rust entry point (the function annotated with #[megaton::main])
*/
inline_always_ void rust_main() {
__megaton_rs_main();
}
}
#endif
24 changes: 8 additions & 16 deletions packages/lib/include/megaton/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
extern "C" {
#endif

// NOLINTNEXTLINE(bugprone-reserved-identifier)
// NOLINTNEXTLINE(bugprone-reserved-identifier) FIXME
extern const char* __megaton_module_name(void);
// NOLINTNEXTLINE(bugprone-reserved-identifier)
// NOLINTNEXTLINE(bugprone-reserved-identifier) FIXME
extern usize __megaton_module_name_len(void);
// NOLINTNEXTLINE(bugprone-reserved-identifier)
// NOLINTNEXTLINE(bugprone-reserved-identifier) FIXME
extern const char* __megaton_title_id_hex(void);
// NOLINTNEXTLINE(bugprone-reserved-identifier)
// NOLINTNEXTLINE(bugprone-reserved-identifier) FIXME
extern u64 __megaton_title_id(void);

#ifdef __cplusplus
Expand All @@ -29,24 +29,16 @@ extern u64 __megaton_title_id(void);
#ifdef __cplusplus
namespace megaton {

/**
* Get the module name.
*/
/** Get the module name. */
inline_always_ const char* module_name() { return __megaton_module_name(); }

/**
* Get the module name length.
*/
/** Get the module name length. */
inline_always_ usize module_name_len() { return __megaton_module_name_len(); }

/**
* Get the title ID in hexadecimal, without the 0x prefix
*/
/** Get the title ID in hexadecimal, without the 0x prefix */
inline_always_ const char* title_id_hex() { return __megaton_title_id_hex(); }

/**
* Get the title ID as a 64-bit integer.
*/
/** Get the title ID as a 64-bit integer. */
inline_always_ u64 title_id() { return __megaton_title_id(); }

} // namespace megaton
Expand Down
50 changes: 0 additions & 50 deletions packages/lib/include/megaton/prelude.h
Original file line number Diff line number Diff line change
@@ -1,62 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2025-2026 Megaton contributors
// * * * * *
// This file was taken from the exlaunch project and modified.
// See original license information below
//
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) shadowninja
// SPDX-License-Identifier: ISC
// Copyright (c) libnx Authors

/**
* prelude.h should be included by all source files.
*
* This includes common primitive types, macros, and attributes
*/
#pragma once

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

typedef uint8_t u8; ///< 8-bit unsigned integer.
typedef uint16_t u16; ///< 16-bit unsigned integer.
typedef uint32_t u32; ///< 32-bit unsigned integer.
typedef uint64_t u64; ///< 64-bit unsigned integer.
typedef __uint128_t u128; ///< 128-bit unsigned integer.

typedef int8_t s8; ///< 8-bit signed integer.
typedef int16_t s16; ///< 16-bit signed integer.
typedef int32_t s32; ///< 32-bit signed integer.
typedef int64_t s64; ///< 64-bit signed integer.
typedef __int128_t s128; ///< 128-bit unsigned integer.

// rust-ish types
typedef s8 i8;
typedef s16 i16;
typedef s32 i32;
typedef s64 i64;
typedef float f32;
typedef double f64;

typedef volatile u8 vu8; ///< 8-bit volatile unsigned integer.
typedef volatile u16 vu16; ///< 16-bit volatile unsigned integer.
typedef volatile u32 vu32; ///< 32-bit volatile unsigned integer.
typedef volatile u64 vu64; ///< 64-bit volatile unsigned integer.
typedef volatile u128 vu128; ///< 128-bit volatile unsigned integer.

typedef volatile s8 vs8; ///< 8-bit volatile signed integer.
typedef volatile s16 vs16; ///< 16-bit volatile signed integer.
typedef volatile s32 vs32; ///< 32-bit volatile signed integer.
typedef volatile s64 vs64; ///< 64-bit volatile signed integer.
typedef volatile s128 vs128; ///< 128-bit volatile signed integer.

typedef size_t usize;


// prelude headers

#include <megaton/types.h>
#include <megaton/attributes.h>
#include <megaton/panic_abort.h>
6 changes: 2 additions & 4 deletions packages/lib/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ name = "megaton-macros"
version = "0.0.0"
edition = "2024"

[dependencies.pm]
package = "pistonite-pm"
version = "0.2.6"
features = ["full"]
[dependencies]
pm = { workspace = true, features = ["full"] }

[lib]
proc-macro = true
Loading
Loading