Skip to content

Commit

Permalink
Merge pull request #48 from Hyrtwol/odin_info
Browse files Browse the repository at this point in the history
How to write odin info as json
  • Loading branch information
Kelimion authored Aug 29, 2024
2 parents 760b259 + 529e13d commit 794d8f7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
odin check glfw/window $FLAGS
odin check json/load_json $FLAGS
odin check json/odin_info $FLAGS
odin check learn_metal/00-window $FLAGS
odin check learn_metal/01-primitive $FLAGS
Expand Down
49 changes: 49 additions & 0 deletions json/odin_info/odin_info.odin
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Demonstrate how you can create a json file
*/
package main

import "base:builtin"
import "base:runtime"
import "core:encoding/json"
import "core:fmt"
import "core:os"

main :: proc() {
fmt.println("Some of Odin's builtin constants")

path := len(os.args) > 1 ? os.args[1] : "odin_info.json"

info: struct {
ODIN_OS: runtime.Odin_OS_Type,
ODIN_ARCH: runtime.Odin_Arch_Type,
ODIN_ENDIAN: runtime.Odin_Endian_Type,
ODIN_VENDOR: string,
ODIN_VERSION: string,
ODIN_ROOT: string,
ODIN_DEBUG: bool,
} = {ODIN_OS, ODIN_ARCH, ODIN_ENDIAN, ODIN_VENDOR, ODIN_VERSION, ODIN_ROOT, ODIN_DEBUG}

fmt.println("Odin:")
fmt.printfln("%#v", info)

fmt.println("JSON:")
json_data, err := json.marshal(info, {
pretty = true,
use_enum_names = true,
})
if err != nil {
fmt.eprintfln("Unable to marshal JSON: %v", err)
os.exit(1)
}

fmt.printfln("%s", json_data)
fmt.printfln("Writing: %s", path)
werr := os.write_entire_file_or_err(path, json_data)
if werr != nil {
fmt.eprintfln("Unable to write file: %v", werr)
os.exit(1)
}

fmt.println("Done")
}

0 comments on commit 794d8f7

Please sign in to comment.