Skip to content

Commit

Permalink
Initial public release
Browse files Browse the repository at this point in the history
  • Loading branch information
thrimbor committed Mar 18, 2024
1 parent d3db6f5 commit 15d3fbf
Show file tree
Hide file tree
Showing 6 changed files with 1,743 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release

on:
push:
tags:
- '*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get version from Cargo.toml
id: get_version
run: echo VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name=="xtlid") | .version') >> $GITHUB_ENV

- name: Log in to crates.io
run: cargo login ${{ secrets.CRATES_IO_TOKEN }}

- name: Publish crate
run: cargo publish

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.VERSION }}
files: src/xtlid.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/src/xtlid.rs
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "xtlid"
version = "0.1.1"
authors = ["Stefan Schmidt"]
edition = "2021"
license = "MIT"
description = "Provides a mapping of IDs to function names for .XTLID-sections found in Xbox executables"

[dependencies]
phf = {version= " 0.11.2", features = ["macros"]}

[build-dependencies]
xmltree = "0.10"
45 changes: 45 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std::fs;
use std::{env, path::Path};
use xmltree::Element;

fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("xtlid.rs");

let input = fs::read_to_string("src/xtlid.xml").unwrap();
let xtlid_element = Element::parse(input.as_bytes()).unwrap();

let mut output = String::new();

output.push_str("use phf::phf_map;\n\n");
output.push_str("pub static XTLIDS: phf::Map<u32, &str> = phf_map! {\n");

for lib_node in xtlid_element.children.iter() {
match lib_node {
xmltree::XMLNode::Element(child_element) => {
if child_element.name == "lib" {
for func_node in child_element.children.iter() {
match func_node {
xmltree::XMLNode::Element(func_node) => {
if func_node.name == "func" {
let id = func_node.attributes.get("id").unwrap();
let name = func_node.attributes.get("name").unwrap();
output.push_str(&format!(" {}u32 => \"{}\",\n", id, name));
}
}
_ => {}
}
}
}
}
_ => {}
}
}

output.push_str("};\n");

fs::write(dest_path, output).unwrap();

println!("cargo:rerun-if-changed=src/xtlid.xml");
println!("cargo:rerun-if-changed=build.rs");
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/xtlid.rs"));
Loading

0 comments on commit 15d3fbf

Please sign in to comment.