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

feat: moved all examples into the main repo #475

Merged
merged 5 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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: 4 additions & 4 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ file(TO_CMAKE_PATH ${mun_examples_path} mun_examples_path)

# Find all mun files
set(mun_folder ${CMAKE_CURRENT_SOURCE_DIR}/..)
file(GLOB_RECURSE mun_test_files RELATIVE ${mun_examples_path} ${mun_examples_path}/*.toml)
file(GLOB_RECURSE mun_project_manifests RELATIVE ${mun_examples_path} ${mun_examples_path}/mun.toml)
set(mun_tests)

foreach (mun_file ${mun_test_files})
get_filename_component(mun_file_dir ${mun_file} DIRECTORY)
set(abs_package_dir ${mun_examples_path}/${mun_file_dir})
foreach (mun_project_manifest ${mun_project_manifests})
get_filename_component(mun_project_manifest_dir ${mun_project_manifest} DIRECTORY)
set(abs_package_dir ${mun_examples_path}/${mun_project_manifest_dir})
set(abs_toml_file ${abs_package_dir}/mun.toml)
set(mun_executable_file mod.munlib)
set(mun_executable_path ${abs_package_dir}/target/${mun_executable_file})
Expand Down
9 changes: 6 additions & 3 deletions cpp/tests/extern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ TEST_CASE("functions must be inserted into the runtime", "[extern]") {
mun::RuntimeOptions options;

mun::Error err;
auto runtime = mun::make_runtime(get_munlib_path("extern/target/mod.munlib"), options, &err);
auto runtime =
mun::make_runtime(get_munlib_path("mun-extern/target/mod.munlib"), options, &err);
REQUIRE(!runtime);
REQUIRE(err.is_error());
}
Expand All @@ -27,7 +28,8 @@ TEST_CASE("function must have correct signature", "[extern]") {
options.functions.emplace_back(mun::RuntimeFunction("extern_fn", some_function));

mun::Error err;
auto runtime = mun::make_runtime(get_munlib_path("extern/target/mod.munlib"), options, &err);
auto runtime =
mun::make_runtime(get_munlib_path("mun-extern/target/mod.munlib"), options, &err);
REQUIRE(!runtime);
REQUIRE(err.is_error());
}
Expand All @@ -37,7 +39,8 @@ TEST_CASE("functions can be inserted into the runtime", "[extern]") {
options.functions.emplace_back(mun::RuntimeFunction("extern_fn", internal_function));

mun::Error err;
auto runtime = mun::make_runtime(get_munlib_path("extern/target/mod.munlib"), options, &err);
auto runtime =
mun::make_runtime(get_munlib_path("mun-extern/target/mod.munlib"), options, &err);
if (!runtime) {
REQUIRE(err.is_error());
FAIL(err.message().value());
Expand Down
6 changes: 3 additions & 3 deletions cpp/tests/marshal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inline std::string get_munlib_path(std::string_view name) {
TEST_CASE("function can marshal " #ty, "[marshal]") { \
mun::Error err; \
if (auto runtime = \
mun::make_runtime(get_munlib_path("marshal/target/mod.munlib"), {}, &err)) { \
mun::make_runtime(get_munlib_path("mun-marshal/target/mod.munlib"), {}, &err)) { \
REQUIRE(err.is_ok()); \
\
const ty a = (lhs), b = (rhs); \
Expand All @@ -29,7 +29,7 @@ inline std::string get_munlib_path(std::string_view name) {
TEST_CASE("struct can get, set, and replace " #ty, "[marshal]") { \
mun::Error err; \
if (auto runtime = \
mun::make_runtime(get_munlib_path("marshal/target/mod.munlib"), {}, &err)) { \
mun::make_runtime(get_munlib_path("mun-marshal/target/mod.munlib"), {}, &err)) { \
REQUIRE(err.is_ok()); \
\
const ty a = (lhs), b = (rhs); \
Expand Down Expand Up @@ -93,7 +93,7 @@ TEST_MARSHALLING(uint64_t, 1, 64, 1 + 64);

TEST_CASE("struct can get, set, and replace struct", "[marshal]") {
mun::Error err;
if (auto runtime = mun::make_runtime(get_munlib_path("marshal/target/mod.munlib"), {}, &err)) {
if (auto runtime = mun::make_runtime(get_munlib_path("mun-marshal/target/mod.munlib"), {}, &err)) {
REQUIRE(err.is_ok());

float a = -3.14f, b = 6.28f;
Expand Down
8 changes: 4 additions & 4 deletions cpp/tests/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ inline std::string get_munlib_path(std::string_view name) {
TEST_CASE("runtime can be constructed", "[runtime]") {
mun::Error err;
if (auto runtime =
mun::make_runtime(get_munlib_path("fibonacci/target/mod.munlib"), {}, &err)) {
mun::make_runtime(get_munlib_path("fibonacci/mun/target/mod.munlib"), {}, &err)) {
REQUIRE(err.is_ok());
} else {
REQUIRE(err.is_error());
Expand All @@ -24,7 +24,7 @@ TEST_CASE("runtime can be constructed", "[runtime]") {
TEST_CASE("runtime can find `FunctionInfo`", "[runtime]") {
mun::Error err;
if (auto runtime =
mun::make_runtime(get_munlib_path("fibonacci/target/mod.munlib"), {}, &err)) {
mun::make_runtime(get_munlib_path("fibonacci/mun/target/mod.munlib"), {}, &err)) {
REQUIRE(err.is_ok());
REQUIRE(runtime.has_value());

Expand All @@ -44,7 +44,7 @@ TEST_CASE("runtime can find `FunctionInfo`", "[runtime]") {
TEST_CASE("runtime can update", "[runtime]") {
mun::Error err;
if (auto runtime =
mun::make_runtime(get_munlib_path("fibonacci/target/mod.munlib"), {}, &err)) {
mun::make_runtime(get_munlib_path("fibonacci/mun/target/mod.munlib"), {}, &err)) {
REQUIRE(err.is_ok());

runtime->update(&err);
Expand All @@ -60,7 +60,7 @@ TEST_CASE("runtime can update", "[runtime]") {

TEST_CASE("runtime can garbage collect", "[runtime]") {
mun::Error err;
if (auto runtime = mun::make_runtime(get_munlib_path("marshal/target/mod.munlib"), {}, &err)) {
if (auto runtime = mun::make_runtime(get_munlib_path("mun-marshal/target/mod.munlib"), {}, &err)) {
REQUIRE(err.is_ok());
{
auto res = mun::invoke_fn<mun::StructRef>(*runtime, "new_bool", true, false);
Expand Down
1 change: 0 additions & 1 deletion crates/mun_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ seq-macro = { version = "0.3.0", default-features = false }
[dev-dependencies]
mun_compiler = { path="../mun_compiler" }
mun_test = { path = "../mun_test" }
bevy = { version = "0.8", default-features = false }
criterion = { version = "0.4", default-features = false }
mlua = { package = "mlua", version = "0.8", default-features = false, features = ["vendored", "luajit"] }
tempfile = { version = "3", default-features = false }
Expand Down
91 changes: 0 additions & 91 deletions crates/mun_runtime/examples/resources/buoyancy.mun

This file was deleted.

11 changes: 0 additions & 11 deletions crates/mun_runtime/examples/resources/fibonacci.mun

This file was deleted.

3 changes: 1 addition & 2 deletions crates/mun_runtime/src/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ impl Assembly {
) -> anyhow::Result<()> {
// Try to link all LUT entries
let mut failed_to_link = false;
for (type_id, type_info_ptr, debug_name) in to_link {
for (type_id, type_info_ptr, _debug_name) in to_link {
// Ensure that the function is in the runtime dispatch table
if let Some(ty) = type_table.find_type_info_by_id(type_id) {
*type_info_ptr = Type::into_raw(ty);
} else {
dbg!(debug_name);
failed_to_link = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_subdirectory(buoyancy)
add_subdirectory(buoyancy/cpp)
3 changes: 3 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
members = ["rust-*", "buoyancy/rust", "fibonacci/rust"]
resolver = "2"
File renamed without changes.
9 changes: 9 additions & 0 deletions examples/buoyancy/cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# C++ buoyancy

A simple example to showcase Mun hotloading.

### How to run?

1. On the CLI, navigate to the `examples/buoyancy/mun` directory.
2. Run the compiler daemon from the CLI to run monitor and build the Mun code: `/path/to/mun build --watch`
3. Run the compiled example application from the CLI: `MunExampleBuoyancy examples/mun-buoyancy/target/mod.munlib`
File renamed without changes.
7 changes: 7 additions & 0 deletions examples/buoyancy/mun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Mun buoyancy

A simple example to showcase Mun hotloading.

### How to run?

Use either the `cpp-buoyancy` or `rust-buoyancy` example to run this code.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions examples/buoyancy/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "buoyancy"
version = "0.1.0"
edition = "2021"

[dependencies]
mun_runtime = { path = "../../../crates/mun_runtime" }
9 changes: 9 additions & 0 deletions examples/buoyancy/rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Rust Buoyancy

A simple example to show how to use Mun.

### How to run?

1. On the CLI, navigate to the `examples/buoyancy/mun` directory.
2. Run the compiler daemon from the CLI: `/path/to/mun build --watch`
3. Run the application from the CLI: `cargo run -p buoyancy -- target/mod.munlib`
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ extern "C" fn log_f32(value: f32) {
println!("{}", value);
}

// How to run?
// 1. On the CLI, navigate to the `crates/mun_runtime/examples` directory.
// 2. Run the compiler daemon from the CLI: `/path/to/mun build resources/buoyancy.mun --watch`
// 3. Run the application from the CLI: cargo run --example buoyancy -- buoyancy.munlib
fn main() {
let lib_dir = env::args().nth(1).expect("Expected path to a Mun library.");

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub fn fibonacci_n() -> i64 {
let n = arg();
let n = nth();
fibonacci(n)
}

pub fn arg() -> i64 {
5
pub fn nth() -> i64 {
10
}

pub fn fibonacci(n: i64) -> i64 {
Expand Down
7 changes: 7 additions & 0 deletions examples/fibonacci/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "fibonacci"
version = "0.1.0"
edition = "2021"

[dependencies]
mun_runtime = { path = "../../../crates/mun_runtime" }
9 changes: 9 additions & 0 deletions examples/fibonacci/rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Rust Fibonacci

A simple example to show how to use Mun.

### How to run?

1. On the CLI, navigate to the `examples/fibonacci/mun` directory.
2. Run the compiler daemon from the CLI: `/path/to/mun build --watch`
3. Run the application from the CLI: `cargo run -p fibonacci -- target/mod.munlib`
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use mun_runtime::Runtime;
use std::env;

// How to run?
// 1. On the CLI, navigate to the `crates/mun_runtime/examples` directory.
// 2. Run the compiler daemon from the CLI: `/path/to/mun build resources/fibonacci.mun --watch`
// 3. Run the application from the CLI: cargo run --example fibonacci -- fibonacci.munlib
fn main() {
let lib_dir = env::args().nth(1).expect("Expected path to a Mun library.");
println!("lib: {}", lib_dir);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/rust-bevy-simple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "bevy-simple"
version = "0.1.0"
edition = "2021"

[dependencies]
mun_runtime = { path = "../../crates/mun_runtime" }
bevy = { version = "0.8", default-features = false }
9 changes: 9 additions & 0 deletions examples/rust-bevy-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Bevy example

A simple example to show how to use Mun with [Bevy](https://bevyengine.org/).

### How to run?

1. On the CLI, navigate to the `examples/rust-bevy-simple/mun` directory.
2. Run the compiler daemon from the CLI: `/path/to/mun build --watch`
3. Run the application from the CLI: `cargo run -p bevy-simple -- target/mod.munlib`
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ use std::{env, path::PathBuf};
use bevy::prelude::*;
use mun_runtime::Runtime as MunRuntime;

// How to run?
// 1. On the CLI, navigate to the `examples/bevy_simple` directory.
// 2. Run the compiler daemon from the CLI: `/path/to/mun build --watch`
// 3. Run the application from the CLI: cargo run --example bevy_simple -- target/mod.munlib

// Minimal Bevy application that demonstrates how to insert the Mun runtime into a Bevy world object and
// utilizes the Mun runtime inside of Bevy systems.
fn main() {
Expand Down
9 changes: 9 additions & 0 deletions examples/rust-pong/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "pong"
version = "0.1.0"
edition = "2021"

[dependencies]
mun_runtime = { path="../../crates/mun_runtime" }
ggez = {version = "0.6" }
rand = "0.8"
12 changes: 12 additions & 0 deletions examples/rust-pong/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Pong example

A simple example to show how to use Mun.

![](screenshot.png)

### How to run?

1. On the CLI, navigate to the `examples/rust-pong/mun` directory.
2. Run the compiler daemon from the CLI: `/path/to/mun build --watch`
3. Open another CLI and navigate to the `examples/rust-pong`.
4. Run the application from the CLI: `cargo run -p pong`
4 changes: 4 additions & 0 deletions examples/rust-pong/mun/mun.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name="pong"
authors=[]
version="0.1.0"
Loading