Skip to content

Commit 330da09

Browse files
authored
Fixing docker build (#87)
- Speedup and simplify docker build - Fix compiler errors when building with clang-15 - Update readme on building with docker - Minor reformatting (using existing `.clang-format` file)
1 parent b765a90 commit 330da09

3 files changed

Lines changed: 61 additions & 22 deletions

File tree

Dockerfile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@ RUN apt-get -y install build-essential
2424
# directory with
2525
# `hyde ./test.hpp -- -x c++ -print-resource-dir`
2626

27+
# FROM base AS full
28+
2729
ENV LLVM_VERSION=15
2830

2931
RUN apt-get -y install clang-${LLVM_VERSION}
30-
31-
# The above doesn't setup libc++ header paths correctly. Currently LLVM-15
32-
# doesn't install with llvm.sh in docker. So we install LLVM-16 just for
33-
# the libc++ config!
34-
35-
RUN wget https://apt.llvm.org/llvm.sh
36-
RUN chmod +x llvm.sh
37-
RUN ./llvm.sh 16 all
32+
RUN apt-get -y install libc++-${LLVM_VERSION}-dev
3833

3934
# set clang ${LLVM_VERSION} to be the version of clang we use when clang/clang++ is invoked
4035
RUN update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} 100
@@ -64,3 +59,7 @@ RUN cp ./build/hyde /usr/bin
6459
# RUN apt-get -y install clang-15
6560

6661
CMD ["./generate_test_files.sh"]
62+
63+
# Experimenting with publishing the container and linking it to the hyde repo:
64+
65+
LABEL org.opencontainers.image.source=https://github.com/adobe/hyde

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,21 @@
3939

4040
LLVM/Clang are declared as a dependency in the project's `CMakeLists.txt` file, and will be downloaded and made available to the project automatically.
4141

42-
# Using Docker
42+
# How to run from Docker
4343

44-
You may need to increase your docker resources to build the image.
44+
```sh
45+
docker pull ghcr.io/adobe/hyde:latest
46+
47+
docker run --platform linux/x86_64 --mount type=bind,source="$(pwd)",target=/mnt/host \
48+
--tty --interactive \
49+
ghcr.io/adobe/hyde:latest bash
50+
```
51+
52+
You can then run the examples as below, except don't prefix `hyde` with `./`.
53+
54+
# Building the Docker image
55+
56+
You may need to increase your docker resources to build the image. (2.0.1 successfully built with 16GB RAM and 4GB swap)
4557

4658
```sh
4759
docker build --tag hyde .
@@ -51,6 +63,20 @@ docker run --platform linux/x86_64 --mount type=bind,source="$(pwd)",target=/mnt
5163
hyde bash
5264
```
5365

66+
# Publishing the docker image (requires write access to the `adobe` GitHub organization)
67+
68+
Instructions for publishing a GitHub package can be found [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).
69+
Instructions for associating the with the `adobe/hyde` repository can be found [here](https://docs.github.com/en/packages/learn-github-packages/connecting-a-repository-to-a-package#connecting-a-repository-to-a-container-image-using-the-command-line).
70+
71+
```sh
72+
VERSION=2.0.1
73+
docker tag hyde ghcr.io/adobe/hyde:$VERSION
74+
docker tag hyde ghcr.io/adobe/hyde:latest
75+
docker push ghcr.io/adobe/hyde:$VERSION
76+
docker push ghcr.io/adobe/hyde:latest
77+
```
78+
79+
5480
# Parameters and Flags
5581

5682
There are several modes under which the tool can run:

sources/autodetect.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ written permission of Adobe.
1313
#include "autodetect.hpp"
1414

1515
// stdc++
16+
#include <algorithm>
1617
#include <array>
17-
#include <random>
18+
#include <cstdio>
1819
#include <fstream>
20+
#include <iterator>
21+
#include <memory>
22+
#include <random>
23+
#include <string>
24+
#include <utility>
25+
#include <vector>
1926

2027
/**************************************************************************************************/
2128

@@ -28,9 +35,11 @@ std::vector<std::string> split(const char* p, std::size_t n) {
2835
std::vector<std::string> result;
2936

3037
while (p != end) {
31-
while (p != end && *p == '\n') ++p; // eat newlines
38+
while (p != end && *p == '\n')
39+
++p; // eat newlines
3240
auto begin = p;
33-
while (p != end && *p != '\n') ++p; // eat non-newlines
41+
while (p != end && *p != '\n')
42+
++p; // eat non-newlines
3443
result.emplace_back(begin, p);
3544
}
3645

@@ -78,22 +87,26 @@ std::string trim_back(std::string s) {
7887

7988
/**************************************************************************************************/
8089

81-
std::string chomp(std::string src) {
82-
return trim_back(trim_front(std::move(src)));
83-
}
90+
std::string chomp(std::string src) { return trim_back(trim_front(std::move(src))); }
8491

8592
/**************************************************************************************************/
8693

8794
std::string exec(const char* cmd) {
88-
std::array<char, 128> buffer;
89-
std::string result;
90-
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
95+
struct pclose_t {
96+
void operator()(std::FILE* p) const { (void)pclose(p); }
97+
};
98+
std::unique_ptr<std::FILE, pclose_t> pipe{popen(cmd, "r")};
99+
91100
if (!pipe) {
92101
throw std::runtime_error("popen() failed!");
93102
}
103+
104+
std::array<char, 128> buffer;
105+
std::string result;
94106
while (fgets(buffer.data(), buffer.size(), pipe.get())) {
95107
result += buffer.data();
96108
}
109+
97110
return chomp(std::move(result));
98111
}
99112

@@ -105,7 +118,8 @@ std::vector<std::filesystem::path> autodetect_include_paths() {
105118
auto temp_dir = std::filesystem::temp_directory_path();
106119
auto temp_out = (temp_dir / ("hyde_" + v + ".tmp")).string();
107120
auto temp_a_out = (temp_dir / ("deleteme_" + v)).string();
108-
auto command = "echo \"int main() { }\" | clang++ -x c++ -v -o " + temp_a_out + " - 2> " + temp_out;
121+
auto command =
122+
"echo \"int main() { }\" | clang++ -x c++ -v -o " + temp_a_out + " - 2> " + temp_out;
109123

110124
auto command_result = std::system(command.c_str());
111125
(void)command_result; // TODO: handle me
@@ -119,14 +133,14 @@ std::vector<std::filesystem::path> autodetect_include_paths() {
119133

120134
if (paths_begin != end(lines) && paths_end != end(lines)) {
121135
lines.erase(paths_end, end(lines));
122-
lines.erase(begin(lines), next(paths_begin));
136+
lines.erase(begin(lines), std::next(paths_begin));
123137

124138
// lines.erase(std::remove_if(begin(lines), end(lines), [](auto& s){
125139
// return s.find(".sdk/") != std::string::npos;
126140
// }), end(lines));
127141

128142
// Some of the paths contain cruft at the end. Filter those out, too.
129-
std::transform(begin(lines), end(lines), std::back_inserter(result), [](auto s){
143+
std::transform(begin(lines), end(lines), std::back_inserter(result), [](auto s) {
130144
static const std::string needle_k{" (framework directory)"};
131145
auto needle_pos = s.find(needle_k);
132146
if (needle_pos != std::string::npos) {

0 commit comments

Comments
 (0)