### Adding Sonic-Mojo Packages via Magic Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Provides bash commands using `magic add` to install the required `libsonic` Rust binary library and the `sonic_mojo` Mojo package. ```Bash # add rust binary lib (required for sonic-mojo) magic add libsonic # add mojopkg magic add sonic_mojo ``` -------------------------------- ### Adding Prefix.dev Channels for Sonic-Mojo Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Provides bash commands using `magic project channel add` to add necessary channels from prefix.dev for installing `libsonic` and `sonic-mojo` packages, including a nightly option. ```Bash # for libsonic magic project channel add "https://repo.prefix.dev/better-ffi" # for sonic-mojo magic project channel add "https://repo.prefix.dev/better-mojo" # for sonic-mojo + nightly magic project channel add "https://repo.prefix.dev/better-mojo-nightly" ``` -------------------------------- ### Release Tasks for Sonic-Mojo Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Defines Ruby Rake tasks for managing the release process, including installing requirements, building the Rust library and Mojo library, and publishing both components. ```Ruby # install requirements magic i # build rust libsonic task br # build mojo lib task bm # publish rust libsonic task publish:ffi # publish mojo lib task publish:mojo ``` -------------------------------- ### Packaging Sonic-Mojo Library Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Provides the bash command `mojo package` to create a Mojo package (`.mojopkg`) for the `sonic` directory, outputting it as `sonic_mojo.mojopkg`. ```Bash mojo package ./sonic -o ./sonic_mojo.mojopkg ``` -------------------------------- ### Running Sonic-Mojo Tests Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Provides bash commands to copy the compiled Rust library, set the `LD_LIBRARY_PATH`, and execute the Mojo test file using `magic shell` and `mojo test`. ```Bash cp ./target/release/libsonic.so ./ magic shell export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(realpath .) mojo test test_sonic.mojo ``` -------------------------------- ### Generating Bindings for Sonic-RS Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Provides the bash command `cargo run --release -- generator` to run the binding generator tool included in the `sonic-rs` project. ```Bash cargo run --release -- generator ``` -------------------------------- ### Compiling Sonic-RS Rust Library Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Provides the bash command `cargo build --release` to compile the required `sonic-rs` Rust library in release mode. ```Bash cargo build --release ``` -------------------------------- ### Define Mojo Package Build and Publish Tasks (Ruby) Source: https://github.com/furnace-dev/sonic-mojo/blob/main/changelog.md Defines Rake tasks for building the Mojo package (`bm`), publishing it to the stable prefix.dev channel (`upm`), and publishing it to the nightly prefix.dev channel (`upmn`). These tasks are likely used within a Rakefile for project automation. ```ruby # build mojopkg task bm # publish to prefix.dev task upm # publish to prefix.dev + nightly task upmn ``` -------------------------------- ### Writing JSON Data with Sonic-Mojo Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Demonstrates how to create or modify a `JsonObject` in Mojo by inserting various data types (bool, u64, i64, string, array, object) using methods like `insert_bool`, `insert_u64`, `insert_i64`, `insert_str`, `insert_array`, and `insert_object`, and how to convert the object back to a string using `to_string`. ```Mojo fn main() raises: # Create a JSON object var o = JsonObject('{"a": {"b": {"c": 100}}}') # Get the nested object var a = o.get_object_mut("a") var b = a.get_object_mut("b") # Read the current value var c = b.get_i64("c") # Output the current value print("Initial value of c: ", c) # Write a new value o.insert_bool("f", True) o.insert_u64("g", 1000000000000000000) o.insert_i64("d", 101) o.insert_str("e", "hello") o.insert_array("h", JsonArray()) o.insert_object("i", JsonObject('{"j": 100}')) # Get the updated object var a_2 = o.get_object_mut("a") # Print the string representation of the nested object print("Updated object a: ", a_2.to_string()) # Print the string representation of the entire JSON object print("Updated JSON object: ", o.to_string()) ``` -------------------------------- ### Updating Internal Library Name Reference Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Provides a bash `sed` command to replace a placeholder library name (`libXXX`) with the correct name (`libsonic`) in a specific internal Mojo file. ```Bash sed -i 's/libXXX/libsonic/g' ./sonic/internal/diplomat_runtime.mojo ``` -------------------------------- ### Reading JSON Data with Sonic-Mojo Source: https://github.com/furnace-dev/sonic-mojo/blob/main/README.md Demonstrates how to parse a JSON string into a `JsonObject` in Mojo and retrieve various data types (i64, u64, bool, string, nested objects, arrays) using methods like `get_i64`, `get_str`, `get_object_mut`, and `get_array_mut`. ```Mojo fn main() raises: # Create a JSON object var o = JsonObject( '{"i64": 1000, "u64": 1000000000000000000, "b": true, "s": "Hi", "obj":' ' {"a": 100, "s": "hello"}, "arr": [1,2,3], "s_arr": ["a", "b", "c"],' ' "null": null}' ) # Reading var i64 = o.get_i64("i64") var u64 = o.get_u64("u64") var b = o.get_bool("b") var s = o.get_str("s") # Reading nested object var obj = o.get_object_mut("obj") var obj_a = obj.get_i64("a") var obj_s = obj.get_str("s") # Reading array var arr = o.get_array_mut("arr") var arr_0 = arr.get_i64(0) var arr_1 = arr.get_i64(1) var arr_2 = arr.get_i64(2) # Reading string array var s_arr = o.get_array_mut("s_arr") var s_arr_len = s_arr.len() var s_arr_0 = s_arr.get_str(0) var s_arr_1 = s_arr.get_str(1) var s_arr_2 = s_arr.get_str(2) # Handling null value var null = o.get_value("null") var i64_2 = o.get_value("i64") # Printing results print("i64: ", i64) print("u64: ", u64) print("bool: ", b) print("string: ", s) print("obj.a: ", obj_a) print("obj.s: ", obj_s) print("arr[0]: ", arr_0) print("arr[1]: ", arr_1) print("arr[2]: ", arr_2) print("s_arr length: ", s_arr_len) print("s_arr[0]: ", s_arr_0) print("s_arr[1]: ", s_arr_1) print("s_arr[2]: ", s_arr_2) print("null is null: ", null.is_null()) print("i64 is null: ", i64_2.is_null()) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.