Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci, codeowners, publish to crates.io #2

Merged
merged 15 commits into from
Nov 14, 2024
Merged
17 changes: 17 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Core components
/kos_core/ @codekansas @hatomist
/daemon/ @codekansas @hatomist

# Platform-specific code
/platforms/kscale_micro/ @codekansas @hatomist
/platforms/kscale_pro/ @codekansas @hatomist @WT-MM
/platforms/sim/ @codekansas @hatomist
/platforms/stub/ @codekansas @hatomist

# Python client
/pykos/ @codekansas @hatomist

# Build and CI configuration
/.github/ @codekansas @hatomist
/toolchain/ @codekansas @hatomist
*.toml @codekansas @hatomist
45 changes: 38 additions & 7 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
image: kos-builder:latest

variables:
CARGO_HOME: $CI_PROJECT_DIR/.cargo
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
TOOLCHAIN_IMAGE: $CI_REGISTRY_IMAGE/toolchain
GIT_SUBMODULE_STRATEGY: recursive

image: $TOOLCHAIN_IMAGE:latest

# Cache dependencies between builds
cache:
Expand All @@ -13,36 +15,63 @@ cache:

# Define stages
stages:
- build-toolchain
- check
- test
- build

.runner: &runner
tags:
- linux-x64

build-toolchain:
<<: *runner
stage: build-toolchain
image: docker:latest

script:
- |
if [ "$GITLAB_CI" != "false" ]; then
echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin
docker pull $TOOLCHAIN_IMAGE:latest || true
fi
- docker build --progress=plain --cache-from $TOOLCHAIN_IMAGE:latest -t $TOOLCHAIN_IMAGE:latest -f toolchain/Dockerfile .
- |
if [ "$GITLAB_CI" != "false" ]; then
docker push $TOOLCHAIN_IMAGE:latest
fi
rules:
- if: $CI_PIPELINE_SOURCE == "push"
changes:
- toolchain/**/*
- .gitlab-ci.yml

# Check formatting and run clippy on all branches
format:
stage: check
script:
- cargo fmt -- --check
- cargo fmt --all -- --check
rules:
- when: always
allow_failure: true

clippy:
stage: check
script:
- cargo clippy -- -D warnings
rules:
- when: always
allow_failure: true

# Test all features
test:
stage: test
script:
- |
if [ "$GITLAB_CI" != "false" ]; then
# CI-specific test commands
cargo test --all-features --verbose
cargo test -F stub --verbose
else
# Local test commands
cargo test
cargo test -F stub
fi
rules:
- when: always
Expand All @@ -59,6 +88,8 @@ test:
- target/$TARGET/release/daemon
rules:
- if: $CI_COMMIT_TAG
when: always
- when: manual

# Linux x86_64
build-linux-x86_64-stub-release:
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "protos/googleapis"]
path = proto/googleapis
url = https://github.com/googleapis/googleapis.git
9 changes: 8 additions & 1 deletion Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ image = "ubuntu:24.04"
pre-build = [
"apt-get update",
"apt-get install -y protobuf-compiler gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential"
]
]

[target.x86_64-unknown-linux-gnu]
image = "ubuntu:24.04"
pre-build = [
"apt-get update",
"apt-get install -y protobuf-compiler build-essential"
]
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
# K-Scale OS

Welcome to the K-Scale Operating System!

## Building

### Prerequisites

- `cross` toolchain

### Native build
Native build with stub features:
```bash
cargo build --features stub
```

### Cross build
Cross build for kbot:
```bash
cross build --release --target aarch64-unknown-linux-gnu --features kscale_pro
```

## Running

```bash
RUST_LOG=debug cargo run --features stub
```

## Contributing
- Use `cargo fmt --all` to format the code.
- Use `cargo clippy` to check for lint errors.
- Use `cargo test` to run the tests.
- Use `tracing` for logging.
- Use `eyre` to handle errors.
- No `unwrap()` or `expect()`.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
38 changes: 22 additions & 16 deletions daemon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
[package]
name = "daemon"
version = "0.1.0"
edition = "2021"
name = "kos"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
description.workspace = true
documentation.workspace = true
readme.workspace = true

[dependencies]
kos_core = { path = "../kos_core" }
kscale_micro = { path = "../platforms/kscale_micro", optional = true }
kos_core = { version = "0.1.1", path = "../kos_core" }
tokio = { version = "1", features = ["full"] }
tonic = { version = "0.12", features = ["transport"] }
eyre = "0.6"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tower = "0.5"

sim = { path = "../platforms/sim", optional = true }
stub = { path = "../platforms/stub", optional = true }
kos-sim = { version = "0.1.0", path = "../platforms/sim", optional = true }
kos-stub = { version = "0.1.0", path = "../platforms/stub", optional = true }
kos-zeroth-01 = { version = "0.1.0", path = "../platforms/zeroth-01", optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
kscale_pro = { path = "../platforms/kscale_pro", optional = true }

# Also can add external platforms here?
# e.g. third_party_platform = { git = "https://github.com/thirdparty/platform", optional = true }
kos-kbot = { version = "0.1.0", path = "../platforms/kbot", optional = true }

[features]
kscale_micro = ["dep:kscale_micro"]
kscale_pro = ["dep:kscale_pro"]
sim = ["dep:sim"]
stub = ["dep:stub"]
default = ["stub"]
kos-zeroth-01 = ["dep:kos-zeroth-01"]
kos-sim = ["dep:kos-sim"]
kos-stub = ["dep:kos-stub"]
default = ["kos-stub"]

[[bin]]
name = "kos"
path = "src/main.rs"
25 changes: 18 additions & 7 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ use tonic::transport::Server;
use tracing::{debug, error, info};
use tracing_subscriber::filter::EnvFilter;

#[cfg(feature = "sim")]
use sim::SimPlatform as PlatformImpl;
#[cfg(not(any(feature = "kos-sim", feature = "kos-zeroth-01", feature = "kos-kbot")))]
use kos_stub::StubPlatform as PlatformImpl;

#[cfg(feature = "stub")]
use stub::StubPlatform as PlatformImpl;
#[cfg(feature = "kos-sim")]
use kos_sim::SimPlatform as PlatformImpl;

#[cfg(feature = "kos-zeroth-01")]
use kos_zeroth_01::Zeroth01Platform as PlatformImpl;

#[cfg(feature = "kos-kbot")]
use kos_kbot::KbotPlatform as PlatformImpl;

fn add_service_to_router(
router: tonic::transport::server::Router,
Expand Down Expand Up @@ -69,14 +75,19 @@ async fn main() -> Result<()> {
)
.init();

let mut platform = PlatformImpl::new();

// telemetry
Telemetry::initialize("test", "localhost", 1883).await?;
Telemetry::initialize(
format!("{}-{}", platform.name(), platform.serial()).as_str(),
"localhost",
1883,
)
.await?;

let operations_store = Arc::new(Mutex::new(HashMap::new()));
let operations_service = Arc::new(OperationsServiceImpl::new(operations_store));

let mut platform = PlatformImpl::new();

platform.initialize(operations_service.clone())?;

if let Err(e) = run_server(&platform, operations_service).await {
Expand Down
10 changes: 8 additions & 2 deletions kos_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[package]
name = "kos_core"
version = "0.1.0"
edition = "2021"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
description.workspace = true
documentation.workspace = true
readme.workspace = true
build = "build.rs"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion kos_core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;

fn main() {
// Path to the Protobuf files
let proto_root = "../proto";
let proto_root = "proto";

// Where to output the compiled Rust files
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
Expand Down
31 changes: 31 additions & 0 deletions kos_core/proto/googleapis/google/api/annotations.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.api;

import "google/api/http.proto";
import "google/protobuf/descriptor.proto";

option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
option java_multiple_files = true;
option java_outer_classname = "AnnotationsProto";
option java_package = "com.google.api";
option objc_class_prefix = "GAPI";

extend google.protobuf.MethodOptions {
// See `HttpRule`.
HttpRule http = 72295728;
}
Loading
Loading