Skip to content

Commit

Permalink
skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
nkia-christoph committed Mar 6, 2024
1 parent cc83764 commit 18909c4
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Cargo.lock
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"EditorConfig.EditorConfig",
"serayuzgur.crates",
"rust-lang.rust-analyzer",
"ms-azuretools.vscode-docker",
"kokakiwi.vscode-just"
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rust-analyzer.hover.actions.references.enable": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.linkedProjects": [
"./Cargo.toml"
]
}
50 changes: 50 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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",
},
]
}
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]
resolver = "2"
members = [
"lib",
"cli",
]
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
106 changes: 106 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "openproject-cli"
version = "0.1.0"
repository = ""
homepage = ""
license = "GPL-3.0-only"
authors = [
"Christoph Kröppl <[email protected]>",
"HMG Software LLC <[email protected]>",
]
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
3 changes: 3 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
31 changes: 31 additions & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "openproject-c-abi"
version = "0.1.0"
repository = ""
homepage = ""
license = "GPL-3.0-only"
authors = [
"Christoph Kröppl <[email protected]>",
"HMG Software LLC <[email protected]>",
]
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
3 changes: 3 additions & 0 deletions lib/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("lol");
}

0 comments on commit 18909c4

Please sign in to comment.