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

feat: add ability to store different versions of plugin #58

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: Tests

on:
push:
branches:
- master
pull_request:
types: [opened, reopened]

jobs:
pre_job:
Expand Down
47 changes: 24 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ name = "cargo-pike"
path = "src/main.rs"

[dev-dependencies]
constcat = "0.6.0"
toml_edit = "0.22.23"
constcat = "0.5.1"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ cargo pike plugin build
#### Доступные опции

- `--release` - Сборка release-версии плагина
- `--target-dir <TARGET_DIR>` - Директория собранных бинарных файлов. Значение по умолчанию: `target`

### `config apply`

Expand Down
4 changes: 2 additions & 2 deletions plugin_template/_Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ serde = { version = "1", features = ["derive"] }
log = "0.4"

[dev-dependencies]
picodata-pike = { git = "https://github.com/picodata/pike.git", branch = "daemon_v2" } # TODO: change after publish on crates.io
picodata-pike = { git = "https://github.com/picodata/pike.git", branch = "more_versions" } # TODO: change after publish on crates.io
reqwest = { version = "0.12", features = ["blocking"] }

[build-dependencies]
picodata-pike = { git = "https://github.com/picodata/pike.git", branch = "daemon_v2" } # TODO: change after publish on crates.io
picodata-pike = { git = "https://github.com/picodata/pike.git", branch = "more_versions" } # TODO: change after publish on crates.io
liquid = "0.26"
fs_extra = "1"

Expand Down
5 changes: 4 additions & 1 deletion src/commands/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{bail, Context, Result};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забудь поправить сообщение коммита

use std::io::{BufRead, BufReader, Read};
use std::path::PathBuf;
use std::process::{Command, Stdio};

pub enum BuildType {
Expand All @@ -8,14 +9,16 @@ pub enum BuildType {
}

#[allow(clippy::needless_pass_by_value)]
pub fn cargo_build(build_type: BuildType) -> Result<()> {
pub fn cargo_build(build_type: BuildType, target_dir: &PathBuf) -> Result<()> {
let mut args = vec!["build"];
if let BuildType::Release = build_type {
args.push("--release");
}

let mut child = Command::new("cargo")
.args(args)
.arg("--target-dir")
.args(target_dir)
.stdout(Stdio::piped())
.spawn()
.context("running cargo build")?;
Expand Down
6 changes: 4 additions & 2 deletions src/commands/plugin/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::path::PathBuf;

use anyhow::{Context, Result};
use lib::{cargo_build, BuildType};

use crate::commands::lib;

pub fn cmd(release: bool) -> Result<()> {
pub fn cmd(release: bool, target_dir: &PathBuf) -> Result<()> {
let build_type = if release {
BuildType::Release
} else {
BuildType::Debug
};
cargo_build(build_type).context("building of plugin")
cargo_build(build_type, target_dir).context("building of plugin")
}
8 changes: 4 additions & 4 deletions src/commands/plugin/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use lib::{cargo_build, BuildType};
use serde::Deserialize;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
use std::path::{Path, PathBuf};
use std::{env, fs};
use tar::Builder;

Expand All @@ -28,7 +28,7 @@ const LIB_EXT: &str = "so";
#[cfg(target_os = "macos")]
const LIB_EXT: &str = "dylib";

pub fn cmd(pack_debug: bool, target_dir: &Path) -> Result<()> {
pub fn cmd(pack_debug: bool, target_dir: &PathBuf) -> Result<()> {
let root_dir = env::current_dir()?;
let plugin_name = &root_dir
.file_name()
Expand All @@ -37,10 +37,10 @@ pub fn cmd(pack_debug: bool, target_dir: &Path) -> Result<()> {
.context("parsing filename to string")?;

let build_dir = if pack_debug {
cargo_build(BuildType::Debug).context("building release version of plugin")?;
cargo_build(BuildType::Debug, target_dir).context("building release version of plugin")?;
Path::new(&root_dir).join(target_dir).join("debug")
} else {
cargo_build(BuildType::Release).context("building debug version of plugin")?;
cargo_build(BuildType::Release, target_dir).context("building debug version of plugin")?;
Path::new(&root_dir).join(target_dir).join("release")
};

Expand Down
4 changes: 2 additions & 2 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ pub fn cluster(params: &Params) -> Result<Vec<PicodataInstance>> {
))?;

let plugins_dir = if params.use_release {
cargo_build(lib::BuildType::Release)?;
cargo_build(lib::BuildType::Release, &params.target_dir)?;
params.target_dir.join("release")
} else {
cargo_build(lib::BuildType::Debug)?;
cargo_build(lib::BuildType::Debug, &params.target_dir)?;
params.target_dir.join("debug")
};

Expand Down
Loading
Loading