From af4e7b5e3d385ea454faa143993648b66d1c389b Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Mon, 16 May 2022 22:20:23 -0600 Subject: [PATCH] Reorganize rust code into crate (for multi-file package) --- .gitignore | 3 ++- Dockerfile | 11 ++++++++--- build.sh | 9 +-------- compile.sh | 9 --------- keymap/rules.mk | 2 +- rust-funcs/.cargo/config.toml | 2 ++ rust-funcs/Cargo.lock | 7 +++++++ rust-funcs/Cargo.toml | 9 +++++++++ rust-funcs/src/lib.rs | 15 +++++++++++++++ {keymap => rust-funcs/src}/pomodoro.rs | 10 ---------- scripts/compile.sh | 10 ++++++++++ 11 files changed, 55 insertions(+), 32 deletions(-) delete mode 100755 compile.sh create mode 100644 rust-funcs/.cargo/config.toml create mode 100644 rust-funcs/Cargo.lock create mode 100644 rust-funcs/Cargo.toml create mode 100644 rust-funcs/src/lib.rs rename {keymap => rust-funcs/src}/pomodoro.rs (95%) create mode 100755 scripts/compile.sh diff --git a/.gitignore b/.gitignore index 466e248..eb68dd2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -out/ \ No newline at end of file +out/ +rust-funcs/target/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 819baa6..9f5b510 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,8 +15,13 @@ run qmk setup -y -H /qmk_firmware run curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -t thumbv7em-none-eabihf -y env PATH="/root/.cargo/bin/:${PATH}" -copy ./compile.sh /usr/bin/compile.sh -run dos2unix /usr/bin/compile.sh -run chmod +x /usr/bin/compile.sh +copy /scripts/compile.sh /opt/compile.sh +run dos2unix /opt/compile.sh +run chmod +x /opt/compile.sh copy ./keymap/* /qmk_firmware/keyboards/massdrop/alt/keymaps/ashe/ +copy ./rust-funcs /rust-funcs/ + run find /qmk_firmware/keyboards/massdrop/alt/keymaps/ashe | xargs dos2unix +run find /rust-funcs/ | xargs dos2unix + +cmd /opt/compile.sh \ No newline at end of file diff --git a/build.sh b/build.sh index 46f103e..3d321db 100755 --- a/build.sh +++ b/build.sh @@ -7,11 +7,4 @@ IMAGE=$(sudo docker build -q .) sudo docker run -it \ --mount type=bind,src=$(pwd)/out,dst=/out \ - $IMAGE \ - sh -c compile.sh - -# cp out/massdrop_alt_ashe.bin ~/bin/Massdrop/qmk/massdrop_alt_ashe.bin -# cd ~/bin/Massdrop/ - -# ./md_loader_windows.exe --first --download ./qmk/massdrop_alt_ashe.bin --restart - + $IMAGE diff --git a/compile.sh b/compile.sh deleted file mode 100755 index 30366da..0000000 --- a/compile.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -cd /qmk_firmware/ -rustc -O --emit=obj --target=thumbv7em-none-eabihf --codegen panic=abort -o pomodoro.o ./keyboards/massdrop/alt/keymaps/ashe/pomodoro.rs - -cd /qmk_firmware -qmk compile -kb massdrop/alt -km ashe -cp massdrop_alt_ashe.bin /out diff --git a/keymap/rules.mk b/keymap/rules.mk index 5030849..362689c 100644 --- a/keymap/rules.mk +++ b/keymap/rules.mk @@ -15,4 +15,4 @@ EXTRAKEY_ENABLE = yes # Audio control and System control # LEADER_ENABLE # Enable leader key chording SRC += lighting_funcs.c -LIB_SRC += pomodoro.o \ No newline at end of file +LIB_SRC += librust_funcs.a \ No newline at end of file diff --git a/rust-funcs/.cargo/config.toml b/rust-funcs/.cargo/config.toml new file mode 100644 index 0000000..51aa8ec --- /dev/null +++ b/rust-funcs/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "thumbv7em-none-eabihf" \ No newline at end of file diff --git a/rust-funcs/Cargo.lock b/rust-funcs/Cargo.lock new file mode 100644 index 0000000..45b6f05 --- /dev/null +++ b/rust-funcs/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rust-funcs" +version = "0.1.0" diff --git a/rust-funcs/Cargo.toml b/rust-funcs/Cargo.toml new file mode 100644 index 0000000..ad91346 --- /dev/null +++ b/rust-funcs/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rust-funcs" +version = "0.1.0" +edition = "2021" + +[dependencies] + +[lib] +crate-type = ["staticlib"] \ No newline at end of file diff --git a/rust-funcs/src/lib.rs b/rust-funcs/src/lib.rs new file mode 100644 index 0000000..a1e4621 --- /dev/null +++ b/rust-funcs/src/lib.rs @@ -0,0 +1,15 @@ +#![no_std] +#![no_builtins] +#![crate_type = "staticlib"] +#![allow(dead_code)] + +mod pomodoro; + +#[panic_handler] +fn my_panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} + + + + diff --git a/keymap/pomodoro.rs b/rust-funcs/src/pomodoro.rs similarity index 95% rename from keymap/pomodoro.rs rename to rust-funcs/src/pomodoro.rs index 95d829d..efc46ad 100644 --- a/keymap/pomodoro.rs +++ b/rust-funcs/src/pomodoro.rs @@ -1,13 +1,3 @@ -#![no_std] -#![no_builtins] -#![crate_type = "staticlib"] -#![allow(dead_code)] - -#[panic_handler] -fn my_panic(_info: &core::panic::PanicInfo) -> ! { - loop {} -} - #[derive(PartialEq, Copy, Clone)] enum PomState { STOPPED, diff --git a/scripts/compile.sh b/scripts/compile.sh new file mode 100755 index 0000000..9788ab5 --- /dev/null +++ b/scripts/compile.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +cd /rust-funcs +cargo build --release +cp ./target/thumbv7em-none-eabihf/release/librust_funcs.a /qmk_firmware/ + +cd /qmk_firmware +qmk compile -kb massdrop/alt -km ashe +cp massdrop_alt_ashe.bin /out