-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker container for c2go #888
Comments
Not that I know of, but it’s a good idea. |
@elliotchance Gotcha! I can take a stab at it, though I'm far from a docker expert. Are there particular versions of clang that you use on your system that you know for sure work with the test examples? |
It been so long since I've worked on c2go that I don't remember which versions I was using. |
At the moment the project seems to not be working with recent versions of clang. Even a simple helloworld.c fails to transpile: Source C $ cat main.c
#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
} Run the command to convert it into Go code:* c2go transpile main.c Error ... panic: unknown node type: 'ColdAttr 0x7f9fe58af708 <col:42>'
goroutine 76 [running]:
github.com/elliotchance/c2go/ast.Parse({0xc00032893a, 0x20})
/Users/drpaneas/gocode/pkg/mod/github.com/elliotchance/[email protected]/ast/ast.go:294 +0x22d4
main.convertLinesToNodes({0xc000333d40, 0xe, 0x0})
/Users/drpaneas/gocode/pkg/mod/github.com/elliotchance/[email protected]/main.go:89 +0x115
main.convertLinesToNodesParallel.func1.2({0xc000333d40, 0x0, 0x0}, 0x0)
/Users/drpaneas/gocode/pkg/mod/github.com/elliotchance/[email protected]/main.go:121 +0x39
created by main.convertLinesToNodesParallel.func1
/Users/drpaneas/gocode/pkg/mod/github.com/elliotchance/[email protected]/main.go:119 +0x2da After a couple hours of debugging I found out that the most recent supported version of clang seems to be:
Since I don't want to mess up my system with different clang versions, I took a docker image that comes with clang 11 (see https://hub.docker.com/r/silkeh/clang/tags) and then I've installed Go and c2go on top. In that way it works in any machine, without worrying about the local system dependencies (well, you need docker obviously). The dockerfile: FROM docker.io/silkeh/clang:11
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get -o Dpkg::Options::="--force-confold" upgrade -q -y --force-yes && \
apt-get -o Dpkg::Options::="--force-confold" dist-upgrade -q -y --force-yes \
&& apt-get install golang-go -q -y --force-yes \
&& mkdir -p ~/go/{bin,src,pkg} \
&& mkdir /code && mkdir /gocode
ENV GOPATH="$HOME/go"
ENV GOBIN="$GOPATH/bin"
ENV GO111MODULE="on"
ENV PATH=$PATH:$GOBIN
RUN go get -u github.com/elliotchance/c2go \
&& echo "#!/usr/bin/env bash" > /gocode/script.sh \
&& echo "\$GOBIN/c2go transpile /code/\$1" >> /gocode/script.sh \
&& echo "NAME=\$(basename \$1 .c)" >> /gocode/script.sh \
&& echo "cat /\$NAME.go" >> /gocode/script.sh \
&& chmod +x /gocode/script.sh
ENTRYPOINT [ "/gocode/script.sh" ] You can run it like this: $ docker run --rm -it -v $PWD:/code docker.io/drpaneas/c2go:v0.26.0 main.c The output now works fine, e.g. see the // removed C types for brevity (it produces a long file)
func main() {
noarch.Printf((&[]byte("Hello, World!\x00")[0]))
return
}
func init() {
stdin = noarch.Stdin
stdout = noarch.Stdout
stderr = noarch.Stderr
} For shortcut (so you don't have to remember the long train-like docker command) you can put a function in our bash/zshell like this (e.g. c2go() {
docker run --rm -it -v $PWD:/code docker.io/drpaneas/c2go:v0.26.0 $1
} then source your file (e.g. Now it works like a charm :) |
@drpaneas you are an absolute hero! I may finally be able to play around with this tool! |
@drpaneas I'm kinda new to docker. My question is how did you get go and then have c2go install in your container ? any help on this. I really would like to get c2go to work. |
The answer is the Dockerfile which I have posted earlier. You can just copy paste it and build it locally. I've literally described the whole process in my previous step. |
@drpaneas thanks for the reply. I did the process you described and got the following error. like I said I'm new to docker. but will love to learn:
executor failed running [/bin/sh -c apt-get update && apt-get -o Dpkg::Options::="--force-confold" upgrade -q -y --force-yes && apt-get -o Dpkg::Options::="--force-confold" dist-upgrade -q -y --force-yes && apt-get install golang-go -q -y --force-yes && mkdir -p ~/go/{bin,src,pkg} && mkdir /code && mkdir /gocode]: exit code: 1 |
I was wondering if someone has worked on a docker container for c2go. I see in a few issues that it can be sensitive to changes in clang. Is there any way to have a docker container with the exact version of clang that is known to work correctly on the test files?
The text was updated successfully, but these errors were encountered: