shiyanhui / libcsp

A concurrency C library 10x faster than Golang.
https://libcsp.dev
MIT License
1.31k stars 74 forks source link

Why you used gcc plugin and benefits? #17

Open emma-eva opened 1 year ago

emma-eva commented 1 year ago

waiting for good answer

emma-eva commented 1 year ago

also build and execute process is hard, plz make it easy

ghost commented 8 months ago

I concur.

I spent 9 hours on this and found what appears to be a dead end:

 > [7/7] RUN bash <<EOF:
0.136 /usr/bin/ld: /tmp/ccLBePAx.o (symbol from plugin): in function `main':
0.136 (.text+0x0): multiple definition of `main'; main.o (symbol from plugin):(.text+0x0): first defined here
0.161 /usr/bin/ld: /tmp/cc1sVYJL.ltrans0.ltrans.o: in function `csp___other_1_csp_main':
0.161 <artificial>:(.text+0x3d): undefined reference to `csp_main'
0.162 collect2: error: ld returned 1 exit status
------
Dockerfile:27
--------------------
  26 |     
  27 | >>> RUN bash <<EOF
  28 | >>>   set -e
  29 | >>>   cspcli init --working-dir=.
  30 | >>>   $CC $CFLAGS -c main.c -o main.o \
  31 | >>>     -fplugin=libcsp -fplugin-arg-libcsp-working-dir=.
  32 | >>>   cspcli analyze --working-dir=.
  33 | >>>   $CC $CFLAGS -o app *.o *.c \
  34 | >>>     -pthread -lcsp
  35 | >>> EOF
  36 |     
--------------------

I have no idea how to debug this further. I give up.

#include <libcsp/csp.h>

#include <stdio.h>

int main() {
  printf("Hi Mom!");
  return 0;
}
FROM debian:bookworm-slim

RUN apt update && apt install -y \
  wget gcc-12 gcc-12-plugin-dev g++-12 make libtool autoconf automake

RUN mkdir app

WORKDIR app

ENV CC="gcc-12"
ENV CXX="g++-12"
ENV CFLAGS="-O3 -flto"

RUN bash <<EOF
  set -e
  wget -q -O libcsp.tar.gz \
    https://github.com/shiyanhui/libcsp/releases/download/v0.0.2/libcsp-0.0.2.tar.gz
  tar -xzvf libcsp.tar.gz
  cd libcsp-0.0.2
  ./configure
  make
  make install
EOF

COPY main.c .

RUN bash <<EOF
  set -e
  cspcli init --working-dir=.
  $CC $CFLAGS -c main.c -o main.o \
    -fplugin=libcsp -fplugin-arg-libcsp-working-dir=.
  cspcli analyze --working-dir=.
  $CC $CFLAGS -o app *.o *.c \
    -pthread -lcsp
EOF

ENTRYPOINT ["app"]