Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ jobs:
cppship init . --name app
test -f .clang-tidy
test -f .clang-format
test -f .gitignore
cppship build
cppship run
cppship test
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(cppship VERSION 0.5.0)
project(cppship VERSION 0.6.0)

# cpp std
set(CMAKE_CXX_STANDARD 20)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A cargo-like modern cpp build tools, aimed to combine all existing best practice

+ dependency management: [conan2](https://conan.io/)
+ you can also directly declare a header-only lib on git as a dependency since we already have tons of such libs
+ you can also directly declare a cppship lib on git as a dependency
+ we will not support import arbitrary libs on git since it will make our package less composable
+ build: [cmake](https://cmake.org/)
+ tests: google test
Expand Down Expand Up @@ -82,6 +83,12 @@ spdlog = "1.11.0"
# git header-only libs
scope_guard = { git = "https://github.com/Neargye/scope_guard.git", commit = "fa60305b5805dcd872b3c60d0bc517c505f99502" }

# git cppship header only lib
header_only = { git = "https://github.com/cppship/demo_header_only.git", commit = "93f6793" }

# git cppship lib
simple_lib = { git = "https://github.com/cppship/demo_lib.git", commit = "25dbedf" }

[dev-dependencies]
scnlib = "1.1.2"

Expand Down
2 changes: 1 addition & 1 deletion cppship.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cppship"
version = "0.5.0"
version = "0.6.0"
authors = []
std = 20

Expand Down
6 changes: 6 additions & 0 deletions include/cppship/cmake/dep.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include "cppship/core/dependency.h"
#include "cppship/core/manifest.h"

#include <string>
#include <vector>

Expand All @@ -10,4 +13,7 @@ struct Dep {
std::vector<std::string> cmake_targets;
};

std::vector<Dep> collect_cmake_deps(
const std::vector<DeclaredDependency>& declared_deps, const ResolvedDependencies& deps);

}
5 changes: 3 additions & 2 deletions include/cppship/cmake/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
namespace cppship {

struct GeneratorOptions {
std::vector<cmake::Dep> deps;
std::vector<cmake::Dep> dev_deps;
std::unique_ptr<cmake::DependencyInjector> injector;
};

class CmakeGenerator {
public:
CmakeGenerator(gsl::not_null<const Layout*> layout, const Manifest& manifest, const ResolvedDependencies& deps,
GeneratorOptions options = {});
CmakeGenerator(gsl::not_null<const Layout*> layout, const Manifest& manifest, GeneratorOptions options = {});

std::string build() &&;

Expand Down
4 changes: 3 additions & 1 deletion include/cppship/cmd/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct BuildContext {
fs::path metafile = root / "cppship.toml";

fs::path conan_file = build_dir / "conanfile.txt";
fs::path git_dep_file = build_dir / "git_dep.toml";
fs::path conan_profile_path = profile_dir / "conan_profile";
fs::path inventory_file = profile_dir / "inventory.toml";
fs::path dependency_file = profile_dir / "dependency.toml";
Expand Down Expand Up @@ -65,7 +66,8 @@ void conan_setup(const BuildContext& ctx);

void conan_install(const BuildContext& ctx);

ResolvedDependencies cppship_install(const BuildContext& ctx);
void cppship_install(
const BuildContext& ctx, const ResolvedDependencies& cppship_deps, const ResolvedDependencies& all_deps);

void cmake_setup(const BuildContext& ctx);

Expand Down
47 changes: 47 additions & 0 deletions include/cppship/core/resolver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include "cppship/core/dependency.h"
#include "cppship/core/manifest.h"

#include <functional>
#include <gsl/pointers>
#include <queue>
#include <set>
#include <vector>

namespace cppship {

struct ResolveResult {
std::vector<DeclaredDependency> conan_dependencies;
std::vector<DeclaredDependency> conan_dev_dependencies;

ResolvedDependencies resolved_dependencies;

std::vector<DeclaredDependency> dependencies;
std::vector<DeclaredDependency> dev_dependencies;
};

// void(std::string_view package, const fs::path& dep_dir, std::string_view git, std::string_view commit)
using GitFetcher = std::function<void(std::string_view, const fs::path&, std::string_view, std::string_view)>;

class Resolver {
public:
Resolver(const fs::path& deps_dir, gsl::not_null<const Manifest*> manifest, GitFetcher fetcher);

ResolveResult resolve() &&;

private:
void do_resolve_(const DeclaredDependency& dep);

void resolve_package_(std::string_view package, const fs::path& package_dir);

private:
fs::path mDepsDir;
gsl::not_null<const Manifest*> mManifest;
GitFetcher mFetcher;
ResolveResult mResult;
std::queue<DeclaredDependency> mUnresolved;
std::set<std::string> mPackageSeen;
};

}
11 changes: 11 additions & 0 deletions include/cppship/util/git.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "cppship/util/fs.h"

#include <string_view>

namespace cppship::util {

void git_clone(std::string_view package, const fs::path& deps_dir, std::string_view git, std::string_view commit);

}
2 changes: 2 additions & 0 deletions include/cppship/util/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace cppship {

void write(const fs::path& file, std::string_view content);

inline void touch(const fs::path& file) { write(file, ""); }

std::string read_as_string(const fs::path& file);

std::string read_as_string(std::istream& iss);
Expand Down
14 changes: 5 additions & 9 deletions lib/cmake/generator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "cppship/cmake/generator.h"
#include "cppship/cmake/bin.h"
#include "cppship/cmake/dep.h"
#include "cppship/cmake/group.h"
#include "cppship/cmake/lib.h"
#include "cppship/cmake/naming.h"
Expand All @@ -22,9 +23,7 @@ using namespace cppship;
using namespace cppship::cmake;
using namespace fmt::literals;

namespace {

std::vector<cmake::Dep> collect_cmake_deps(
std::vector<cmake::Dep> cmake::collect_cmake_deps(
const std::vector<DeclaredDependency>& declared_deps, const ResolvedDependencies& deps)
{
std::vector<cmake::Dep> result;
Expand Down Expand Up @@ -62,14 +61,11 @@ std::vector<cmake::Dep> collect_cmake_deps(
return result;
}

}

CmakeGenerator::CmakeGenerator(gsl::not_null<const Layout*> layout, const Manifest& manifest,
const ResolvedDependencies& deps, GeneratorOptions options)
CmakeGenerator::CmakeGenerator(gsl::not_null<const Layout*> layout, const Manifest& manifest, GeneratorOptions options)
: mLayout(layout)
, mManifest(manifest)
, mDeps(collect_cmake_deps(manifest.dependencies(), deps))
, mDevDeps(collect_cmake_deps(manifest.dev_dependencies(), deps))
, mDeps(std::move(options.deps))
, mDevDeps(std::move(options.dev_deps))
, mInjector(std::move(options.injector))
{
}
Expand Down
Loading