Skip to content

Commit

Permalink
Fixing docker build (#87)
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
sean-parent authored Jun 11, 2024
1 parent b765a90 commit 330da09
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ RUN apt-get -y install build-essential
# directory with
# `hyde ./test.hpp -- -x c++ -print-resource-dir`

# FROM base AS full

ENV LLVM_VERSION=15

RUN apt-get -y install clang-${LLVM_VERSION}

# The above doesn't setup libc++ header paths correctly. Currently LLVM-15
# doesn't install with llvm.sh in docker. So we install LLVM-16 just for
# the libc++ config!

RUN wget https://apt.llvm.org/llvm.sh
RUN chmod +x llvm.sh
RUN ./llvm.sh 16 all
RUN apt-get -y install libc++-${LLVM_VERSION}-dev

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

CMD ["./generate_test_files.sh"]

# Experimenting with publishing the container and linking it to the hyde repo:

LABEL org.opencontainers.image.source=https://github.com/adobe/hyde
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,21 @@

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.

# Using Docker
# How to run from Docker

You may need to increase your docker resources to build the image.
```sh
docker pull ghcr.io/adobe/hyde:latest

docker run --platform linux/x86_64 --mount type=bind,source="$(pwd)",target=/mnt/host \
--tty --interactive \
ghcr.io/adobe/hyde:latest bash
```

You can then run the examples as below, except don't prefix `hyde` with `./`.

# Building the Docker image

You may need to increase your docker resources to build the image. (2.0.1 successfully built with 16GB RAM and 4GB swap)

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

# Publishing the docker image (requires write access to the `adobe` GitHub organization)

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).
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).

```sh
VERSION=2.0.1
docker tag hyde ghcr.io/adobe/hyde:$VERSION
docker tag hyde ghcr.io/adobe/hyde:latest
docker push ghcr.io/adobe/hyde:$VERSION
docker push ghcr.io/adobe/hyde:latest
```


# Parameters and Flags

There are several modes under which the tool can run:
Expand Down
38 changes: 26 additions & 12 deletions sources/autodetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ written permission of Adobe.
#include "autodetect.hpp"

// stdc++
#include <algorithm>
#include <array>
#include <random>
#include <cstdio>
#include <fstream>
#include <iterator>
#include <memory>
#include <random>
#include <string>
#include <utility>
#include <vector>

/**************************************************************************************************/

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

while (p != end) {
while (p != end && *p == '\n') ++p; // eat newlines
while (p != end && *p == '\n')
++p; // eat newlines
auto begin = p;
while (p != end && *p != '\n') ++p; // eat non-newlines
while (p != end && *p != '\n')
++p; // eat non-newlines
result.emplace_back(begin, p);
}

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

/**************************************************************************************************/

std::string chomp(std::string src) {
return trim_back(trim_front(std::move(src)));
}
std::string chomp(std::string src) { return trim_back(trim_front(std::move(src))); }

/**************************************************************************************************/

std::string exec(const char* cmd) {
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
struct pclose_t {
void operator()(std::FILE* p) const { (void)pclose(p); }
};
std::unique_ptr<std::FILE, pclose_t> pipe{popen(cmd, "r")};

if (!pipe) {
throw std::runtime_error("popen() failed!");
}

std::array<char, 128> buffer;
std::string result;
while (fgets(buffer.data(), buffer.size(), pipe.get())) {
result += buffer.data();
}

return chomp(std::move(result));
}

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

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

if (paths_begin != end(lines) && paths_end != end(lines)) {
lines.erase(paths_end, end(lines));
lines.erase(begin(lines), next(paths_begin));
lines.erase(begin(lines), std::next(paths_begin));

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

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

0 comments on commit 330da09

Please sign in to comment.