otobrglez / compression-puzzle

Attempts to crack the "compression puzzle".
15 stars 47 forks source link

Add Gregg's Red solution. #25

Closed greggirwin closed 2 years ago

otobrglez commented 2 years ago

Hey greggirwin!

Thank you for your submission! Love it!

Can u give me some pointers on how to run/compile this thing? :)

greggirwin commented 2 years ago

@rebolek, I think, found a solution to using Docker. As I noted to @refaktor there is a great irony to Red being a single EXE and standalone toolchain, then having problems with other things. :^\ We can start with the obvious.

First, are you on a system with 32-bit support. Red isn't 64-bit yet, so modern MacOS doesn't like it, and some nix systems need libs installed.

1) Do you have Red's automated build installed (stable is pretty old, but automated is still robust)? 2) Does it run and auto-build the console on your system when you just run Red? May take 30s or so, since it compiles the entire runtime as well. 3) Does the console run for you? Once built, running Red should start that by default. i.e. if you're not compiling. For the non-GUI console, use --cli on the command line. 4) If you got this far, do %compress-gregg.red in the console. Include the path if necessary. 5) At this point, we know Red works on your system. Woohoo!

We can talk compiling once we have this baseline and some confidence. :^)

refaktor commented 2 years ago

Cool solution with the use of series and charsets @greggirwin, two very red/bol specific features. :)

About running. If I tested correctly I think the Red's automated build needs GUI display to be present in the system, while Red 0.6.4 didn't. I am not a Docker or Red expert but most typical (linux) dockers have only console, no X. I managed to run 0.6.4 https://hub.docker.com/r/kskarthik/redlang without problems, but when I modified it for latest Red I got the "Unable to init server: Could not connect: Connection refused (console-2022-2-2-55094:9): Gtk-WARNING **: 07:58:44.680: cannot open display:" error. Even if I run with --cli and --no-view. I remember solutions like Xvfb in this area, but by quick try I didn't managed to make it work and I forgot how exactly to use it.

Based on this, I think that latest Red should really be run in a docker like you were setting up @otobrglez , for Selenium project, which has a real or virtual X and all. But adding to it the i386 support from kskarthik script. The ^@^@ error could be some 32bit disc driver problem if I understood correctly. We were testing this with 0.6.4 , that worked on my setup. Maybe latest won't have this problem.

Thank you for all your work @otobrglez ... I am thinking if I should also install nix to test the exact same setup as you have to try to solve this. I will contact you in chat.

refaktor commented 2 years ago

I managed to run latest Red on a docker without X using Xvfb. I am testing how to turn it into docker image.

refaktor commented 2 years ago

This is the Docker file for running latest Red build https://gist.github.com/refaktor/d05d550d20fb882c74c70104fd929bfb

It can probably be improved by someone who knows Docker :).

It runs Red once inside docker build process, so Red compiles Red console and stores that state. Otherwise this needs to be done each time you restart a container. During the initial build Red still throws the GTK error, I wasn't able to fix that.

For those new to Docker: If you save this as a local file "Docker" you build it with:

sudo docker build -t red-latest -f Docker .

And then run it with:

sudo docker run -ti red-latest

When in container console you need to start Xvfb with:

Xvfb :99 &

This can probably be automated but I haven found out how yet. Then red will run.

red
red hello.red
rebolek commented 2 years ago

Here’s the Dockerfile that I use:

FROM debian:unstable-slim
ENV TERM=xterm LANG=C.UTF-8 LC_ALL=C.UTF-8
WORKDIR .
RUN dpkg --add-architecture i386 && apt-get update -qq && \
        apt-get upgrade -yqq && apt-get install -yqq \
        --no-install-recommends curl git libc6:i386 libcurl4:i386 \
        libgdk-pixbuf2.0-0:i386 && \
        apt-get install -yqq --reinstall ca-certificates
RUN curl http://www.rebol.com/downloads/v278/rebol-core-278-4-3.tar.gz \
        | tar zxv && mv releases/rebol-core/rebol bin/  && rm -rf releases
RUN git clone https://github.com/red/red.git && cd red && \
        echo 'Rebol[]\ndo/args %red.r "-r environment/console/CLI/console.red"\n' \
        > build-red.r
RUN cd red && rebol build-red.r && mv console /bin/red
ENTRYPOINT ["red"]

and I run Red with

docker run -it  -w /red -v "$(pwd):/red" red

It’s certainly not the best because I would prefer to have the same path in Docker as in the host system and some Ctrl+C behavior can be better, but that’s the best I was able to come up with, as I know almost nothing about Docker.

dander commented 2 years ago

@rebolek you could put WORKDIR /red toward the end, and not need to pass in -w.

I would prefer to have the same path in Docker as in the host system

I don't know of any way to do this. Docker also has another annoyance which is that it runs as root by default, so if you use it for compilation, for example, your output files will belong to root:root.

@refaktor A trick I like for compiling the console from the red toolchain is RUN echo "quit" | red

rebolek commented 2 years ago

@dander it’s possible to do in Multipass: https://github.com/rebolek/red-tools/wiki/Red-on-Catalina

otobrglez commented 2 years ago

As you guys managed to find a way in separate PR; I'm closing this one.

Thank you!