Skip to content

Commit 2687ba3

Browse files
authored
Support system dependencies (#827)
Closes #813
1 parent 4091062 commit 2687ba3

22 files changed

+895
-100
lines changed

.github/workflows/codeql.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ jobs:
5959
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
6060
# queries: security-extended,security-and-quality
6161

62+
- name: Install dependencies
63+
run: |
64+
sudo apt-get update
65+
sudo apt-get install -y \
66+
libgit2-dev
67+
6268
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
6369
# If this step fails, then you should remove it and run the build manually (see below)
6470
- name: Autobuild

.github/workflows/cpp.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ jobs:
5151
steps:
5252
- uses: actions/checkout@v4
5353

54+
- name: Install dependencies
55+
run: |
56+
sudo apt-get update
57+
sudo apt-get install -y \
58+
libgit2-dev
59+
5460
- name: Build Poac
5561
run: make RELEASE=1
5662

.github/workflows/linux.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ jobs:
4343
chmod +x ./llvm.sh
4444
sudo ./llvm.sh ${{ matrix.compiler.ver }}
4545
46+
- name: Install dependencies
47+
run: |
48+
sudo apt-get update
49+
sudo apt-get install -y \
50+
libgit2-dev
51+
4652
- name: First Generation Build
4753
run: make -j4
4854

.github/workflows/macos.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ jobs:
2222
steps:
2323
- uses: actions/checkout@v4
2424

25+
- name: Install dependencies
26+
run: |
27+
brew install \
28+
libgit2
29+
2530
- name: First Generation Build
2631
run: make -j4
2732

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ PROJ_NAME = $(OUT_DIR)/poac
1616
VERSION = $(shell grep -m1 version poac.toml | cut -f 2 -d'"')
1717

1818
DEFINES = -DPOAC_VERSION='"$(VERSION)"'
19-
INCLUDES = -I$(OUT_DIR)/DEPS/toml11
19+
INCLUDES = -I$(OUT_DIR)/DEPS/toml11 $(shell pkg-config --cflags libgit2)
20+
LIBS = $(shell pkg-config --libs libgit2)
2021

2122
SRCS = $(shell find src -name '*.cc')
2223
OBJS = $(patsubst src/%,$(OUT_DIR)/%,$(SRCS:.cc=.o))
@@ -57,7 +58,7 @@ $(OUT_DIR)/DEPS:
5758

5859

5960
$(PROJ_NAME): $(OBJS)
60-
$(CXX) $(CXXFLAGS) $^ -o $@
61+
$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@
6162

6263
$(OUT_DIR)/%.o: src/%.cc
6364
$(CXX) $(CXXFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@
@@ -77,20 +78,20 @@ $(OUT_DIR)/tests/test_%.d: src/%.cc | $(OUTSIDE_DEPS) $(OUT_DIR) $(OUT_DIR)/test
7778

7879
$(OUT_DIR)/tests/test_BuildConfig: $(OUT_DIR)/tests/test_BuildConfig.o \
7980
$(OUT_DIR)/Logger.o $(OUT_DIR)/TermColor.o $(OUT_DIR)/Manifest.o \
80-
$(OUT_DIR)/Semver.o
81-
$(CXX) $(CXXFLAGS) $^ -o $@
81+
$(OUT_DIR)/Semver.o $(OUT_DIR)/Algos.o $(OUT_DIR)/VersionReq.o
82+
$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@
8283

8384
$(OUT_DIR)/tests/test_Algos: $(OUT_DIR)/tests/test_Algos.o $(OUT_DIR)/Logger.o \
8485
$(OUT_DIR)/TermColor.o
85-
$(CXX) $(CXXFLAGS) $^ -o $@
86+
$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@
8687

8788
$(OUT_DIR)/tests/test_Semver: $(OUT_DIR)/tests/test_Semver.o $(OUT_DIR)/Logger.o \
8889
$(OUT_DIR)/TermColor.o
89-
$(CXX) $(CXXFLAGS) $^ -o $@
90+
$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@
9091

9192
$(OUT_DIR)/tests/test_VersionReq: $(OUT_DIR)/tests/test_VersionReq.o \
9293
$(OUT_DIR)/Logger.o $(OUT_DIR)/TermColor.o $(OUT_DIR)/Semver.o
93-
$(CXX) $(CXXFLAGS) $^ -o $@
94+
$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@
9495

9596

9697
$(OUT_DIR)/tests/test_%.o: src/%.cc

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,19 @@ If your environment is not included in the released packages, you have to build
8383
#### Commands
8484

8585
* make
86+
* pkg-config
8687
* find
8788
* grep
8889
* mkdir
8990
* rm
9091

9192
#### Libraries
9293

94+
* libgit2
95+
9396
When running Make, the following libraries will be installed automatically.
9497

95-
* [`toml11`](https://github.com/ToruNiina/toml11): [`9086b11`](https://github.com/ToruNiina/toml11/commit/9086b1114f39a8fb10d08ca704771c2f9f247d02) or later
98+
* [toml11](https://github.com/ToruNiina/toml11): [`9086b11`](https://github.com/ToruNiina/toml11/commit/9086b1114f39a8fb10d08ca704771c2f9f247d02) or later
9699
* requires [this commit](https://github.com/ToruNiina/toml11/commit/9086b1114f39a8fb10d08ca704771c2f9f247d02)
97100
* awaiting the next release above [`v3.7.1`](https://github.com/ToruNiina/toml11/releases/tag/v3.7.1)
98101

@@ -106,8 +109,9 @@ make RELEASE=1 install
106109

107110
### Runtime Requirements
108111

109-
* Make
110112
* C++ compiler
113+
* Make
114+
* pkg-config
111115
* mkdir
112116
* echo
113117
* Git (for Git dependencies)

poac.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ version = "0.7.0"
1212

1313
[dependencies]
1414
"ToruNiina/toml11" = {git = "https://github.com/ToruNiina/toml11.git", rev = "846abd9a49082fe51440aa07005c360f13a67bbf"}
15-
16-
[profile.release]
17-
lto = true
15+
libgit2 = {version = "1.1.0", system = true}
1816

1917
[lint.cpplint]
2018
filters = [

src/Algos.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
#include <memory>
77
#include <utility>
88

9+
String execShell(StringRef cmd) {
10+
std::array<char, 128> buffer;
11+
String result;
12+
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.data(), "r"), pclose);
13+
if (!pipe) {
14+
throw std::runtime_error("popen() failed!");
15+
}
16+
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
17+
result += buffer.data();
18+
}
19+
return result;
20+
}
21+
922
// O(M) where M is the length of the word.
1023
void trieInsert(TrieNode& root, StringRef word) {
1124
TrieNode* node = &root;

src/Algos.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <stdexcept>
1313
#include <utility>
1414

15+
String execShell(StringRef);
16+
1517
template <typename... Args>
1618
inline String concat(Args&&... args) {
1719
return (std::ostringstream{} << ... << std::forward<Args>(args)).str();

src/BuildConfig.cc

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ static String OUT_DIR;
2626
static constexpr StringRef TEST_OUT_DIR = "tests";
2727
static const String PATH_FROM_OUT_DIR = "../..";
2828
static String CXX = "clang++";
29-
static String INCLUDES = "-Iinclude";
3029
static String DEFINES;
30+
static String INCLUDES = " -Iinclude";
31+
static String LIBS;
3132

3233
void setOutDir(const bool isDebug) {
3334
if (isDebug) {
@@ -43,19 +44,6 @@ String getOutDir() {
4344
return OUT_DIR;
4445
}
4546

46-
static String exec(const char* cmd) {
47-
std::array<char, 128> buffer;
48-
String result;
49-
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
50-
if (!pipe) {
51-
throw std::runtime_error("popen() failed!");
52-
}
53-
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
54-
result += buffer.data();
55-
}
56-
return result;
57-
}
58-
5947
static Vec<Path> listSourceFilePaths(StringRef directory) {
6048
Vec<Path> sourceFilePaths;
6149
for (const auto& entry : fs::recursive_directory_iterator(directory)) {
@@ -293,7 +281,7 @@ String runMM(const String& sourceFile, const bool isTest = false) {
293281
} else {
294282
command += " -MM " + sourceFile;
295283
}
296-
return exec(command.c_str());
284+
return execShell(command);
297285
}
298286

299287
static OrderedHashSet<String>
@@ -390,7 +378,7 @@ static void defineLinkTarget(
390378
) {
391379
Vec<String> commands(2);
392380
commands[0] = echoCmd("Linking", binTarget);
393-
commands[1] = buildCmd("$(CXX) $(CXXFLAGS) $^ -o $@");
381+
commands[1] = buildCmd("$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@");
394382
config.defineTarget(binTarget, commands, deps);
395383
}
396384

@@ -468,18 +456,15 @@ static void setVariables(BuildConfig& config, const bool isDebug) {
468456
+ getPackageVersion().to_string() + "\"'";
469457
config.defineSimpleVariable("DEFINES", DEFINES);
470458

471-
const Vec<Path> deps = installGitDependencies();
472-
for (const Path& dep : deps) {
473-
const Path includeDir = dep / "include";
474-
if (fs::exists(includeDir) && fs::is_directory(includeDir)
475-
&& !fs::is_empty(includeDir)) {
476-
INCLUDES += " -I" + includeDir.string();
477-
} else {
478-
INCLUDES += " -I" + dep.string();
479-
}
459+
const Vec<DepMetadata> deps = installDependencies();
460+
for (const DepMetadata& dep : deps) {
461+
INCLUDES += ' ' + dep.includes;
462+
LIBS += ' ' + dep.libs;
480463
}
481464
Logger::debug("INCLUDES: ", INCLUDES);
465+
Logger::debug("LIBS: ", LIBS);
482466
config.defineSimpleVariable("INCLUDES", INCLUDES);
467+
config.defineSimpleVariable("LIBS", LIBS);
483468
}
484469

485470
static BuildConfig configureBuild(const bool isDebug) {

0 commit comments

Comments
 (0)