diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b86b0bd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +trim_trailing_whitespace = true +max_line_length = 80 +indent_size = 4 + +[Makefile] +indent_style = tab + +[*.{json,ron,yaml}] +max_line_length = 120 +indent_size = 2 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9d37c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..80cfddc --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,9 @@ +{ + "recommendations": [ + "EditorConfig.EditorConfig", + "serayuzgur.crates", + "rust-lang.rust-analyzer", + "ms-azuretools.vscode-docker", + "kokakiwi.vscode-just" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..aa4119b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "rust-analyzer.hover.actions.references.enable": true, + "rust-analyzer.check.command": "clippy", + "rust-analyzer.linkedProjects": [ + "./Cargo.toml" + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7a60c2c --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,50 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "setup", + "linux": { + "command": "just", + "args": ["setup"], + }, + "type": "shell", + "group": "build", + }, + { + "label": "test", + "linux": { + "command": "just", + "args": ["test"], + }, + "type": "shell", + "group": "test", + }, + { + "label": "build", + "linux": { + "command": "just", + "args": ["build-dev"], + }, + "type": "shell", + "group": "build", + }, + { + "label": "install", + "linux": { + "command": "just", + "args": ["install-dev"], + }, + "type": "shell", + "group": "build", + }, + { + "label": "lint", + "linux": { + "command": "just", + "args": ["lint-dev"], + }, + "type": "shell", + "group": "test", + }, + ] +} diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8819475 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +resolver = "2" +members = [ + "lib", + "cli", +] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1fe91e6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# syntax=docker/dockerfile:1 +FROM messense/cargo-zigbuild:latest AS base + +RUN mkdir /io +RUN echo "installing just..." +RUN curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin + +FROM base AS just +RUN echo "just installed." + +RUN echo "copying src..." +COPY --link Cargo.toml /io/. +COPY --link Cargo.lock /io/. +COPY --link cli /io/. +COPY --link lib /io/. +COPY --link Justfile /io/. + +FROM just AS loaded +RUN echo "src copied." + +RUN echo "building binaries..." +WORKDIR /io + +RUN /usr/local/bin/just build diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..27a71e7 --- /dev/null +++ b/Justfile @@ -0,0 +1,106 @@ +default: build-dev + + +alias b := build-dev +alias i := install-dev +alias l := lint-dev + + +export RUST_BACKTRACE := "1" +export RUST_LOG := "debug" + + +cli := "openproject-cli" +lib := "libOpenProject.so" +target_dev := if os() == "linux" { + "x86_64-unknown-linux-gnu" +} else if os() == "mac" { + "universal2-apple-darwin" +} else { + error("Unsupported OS: {{ os() }}; only supporting {{ supported_os }}") +} +# TODO: replace with command in backticks; figure out why x86_64-unknown-linux-gnu breaks +# https://just.systems/man/en/chapter_33.html#command-evaluation-using-backticks +target_release := """ + aarch64-apple-darwin + aarch64-unknown-linux-gnu + universal2-apple-darwin + x86_64-apple-darwin + x86_64-unknown-linux-gnu +""" + + +set ignore-comments +set shell := ["bash", "-c"] + + +# build for the local machine +build-dev: install-rustup zigbuild setup lint-dev + @echo "Compiling development binaries for target: {{ target_dev }}" + cargo zigbuild --target {{ target_dev }} + +# build for all supported targets in docker +build: setup + @echo "Cross-compiling binaries..." + @for target in $(echo "{{ target_release }}" | sed "s/\n/ /g"); do \ + echo "Compiling release binaries for target: ${target}"; \ + cargo zigbuild --release --target ${target}; \ + done + echo "Compilation completed"; + + +# install the cli and library to the local machine +install-dev: build-dev + # https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#:~:text=3.1.1.%20Shared%20Library%20Names + install -Dm755 target/{{ cli }} /bin/{{ cli }} + install -Dm755 target/{{ lib }} /usr/lib/{{ lib }} + +# Install rustup if rustc or cargo are not installed +install-rustup: + @if command -v rustc &> /dev/null || command -v cargo &> /dev/null; then \ + echo "Rustc and Cargo are already installed"; \ + else \ + echo "Installing rustup (rustc & cargo)"; \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh; \ + fi + +check: + cargo fmt -- --check + +lint: + cargo clippy --all-targets --all-features -- -D warnings + +# lint with pedantic warnings +lint-dev: check + cargo clippy --all-targets --all-features -- -D warnings -W clippy::pedantic + cargo clippy --fix + +publish: test + cargo publish + +# build and publish to crates.io +release: build publish + +# install rustup, rustc, cargo, and cross-compilation targets +setup: + @echo "Setup" + @for target in $(echo "{{ target_release }}" | sed "s/\n/ /g"); do \ + if [[ ${target} =~ "universal" ]]; then \ + echo "Skipping toolchain installation for: ${target}"; \ + continue; \ + fi; \ + echo "Adding toolchain and build target: ${target}"; \ + rustup toolchain install --force-non-host stable-${target} --component clippy; \ + rustup target add --toolchain stable-${target} ${target}; \ + echo "Finished ${target}" && echo ""; \ + done + +test: + cargo test + +zigbuild: + echo "Installing cargo-zigbuild" + @if ! command -v "cargo install cargo-zigbuild" &> /dev/null; then \ + echo "Installing cargo-zigbuild"; \ + cargo install cargo-zigbuild; \ + fi diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000..daded3c --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "openproject-cli" +version = "0.1.0" +repository = "" +homepage = "" +license = "GPL-3.0-only" +authors = [ + "Christoph Kröppl ", + "HMG Software LLC ", +] +edition = "2021" +keywords = ["cli", "client", "op", "openproject"] +categories = ["command-line-utilities", "database"] + +[dependencies] +clap = "4" + +[dev-dependencies] +clippy = "*" + +[build-dependencies] +cargo-zigbuild = "0" + +[[bin]] +name = "openproject-cli" +path = "src/main.rs" + +[profile.release] +codegen-units = 1 +lto = true +strip = true +debug = false diff --git a/cli/src/main.rs b/cli/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/cli/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/lib/Cargo.toml b/lib/Cargo.toml new file mode 100644 index 0000000..b0fe3a7 --- /dev/null +++ b/lib/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "openproject-c-abi" +version = "0.1.0" +repository = "" +homepage = "" +license = "GPL-3.0-only" +authors = [ + "Christoph Kröppl ", + "HMG Software LLC ", +] +edition = "2021" +keywords = ["abi", "ffi", "lib", "op", "openproject"] +categories = ["development-tools", "database"] + +[dependencies] +reqwest = "0" + +[dev-dependencies] +clippy = "*" + +[build-dependencies] +cargo-zigbuild = "0" + +[[bin]] +name = "libopc" +path = "src/main.rs" + +[profile.release] +codegen-units = 1 +lto = true +strip = true diff --git a/lib/src/main.rs b/lib/src/main.rs new file mode 100644 index 0000000..6ca9d92 --- /dev/null +++ b/lib/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("lol"); +}