[bug#72494,0/1] Add C3

Message ID cover.1722933384.git.ashvithshetty10@gmail.com
Headers
Series Add C3 |

Message

Ashvith Shetty Aug. 6, 2024, 11:02 a.m. UTC
This patch series adds C3, which is a programming language that builds on the syntax and semantics of the C language, with the goal of evolving it while still retaining familiarity for C programmers.

Tests have been disabled, as I was not able to figure out on how to make it work, but I would appreciate it, if anyone is willing to improve this patch series.

Ashvith Shetty (1):
  gnu: Add C3 1.6.1.

 gnu/packages/c3.scm | 59 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 gnu/packages/c3.scm


base-commit: b20956651a53a8f23828fdeb6945e1a31e6997a8
  

Comments

Adam Faiz Aug. 6, 2024, 3:07 p.m. UTC | #1
Hello Ashvith,

I'd like to give my feedback on this patch series. I'll send an updated patch series using the suggestions below if I have the time.

> +(define-public c3c-bootstrap
> +  (package
> +    (name "c3c")
> +    (version "0.6.1")
> +    (source
> +     (origin
> +       (method git-fetch)
> +       (uri (git-reference
> +             (url "https://github.com/c3lang/c3c")
> +             (commit (string-append "v" version))))
> +       (file-name (git-file-name name version))
> +       (sha256
> +        (base32 "0xjl3yghyqmqv9118nhcix3xywlpdirqc0dlmdaghdkja0wr19rw"))
> +       (snippet #~(begin
> +                    (use-modules (guix build utils))
> +                    (substitute* "CMakeLists.txt"
> +                      (("\\$\\{LLVM_LIBRARY_DIRS\\}")
> +                       (string-append #$lld-18 "/lib/ "
> +                                      #$llvm-18 "/lib/")))))))
> +    (build-system cmake-build-system)
> +    (arguments
> +     '(#:configure-flags '("-DCMAKE_INSTALL_LIBDIR=lib")
> +       ;; TODO: Fix test
> +       #:tests? #f))

According to its README, the unit tests are run using the built c3c with its compile-test subcommand: `c3c compile-test test/unit`. The `check` build phase needs to be replaced to run this command.

A patch sent upstream to add a proper `check` target would be good, and the test/ subdirectory would probably also need to be specified as part of the out-of-tree build.

> +    (inputs (list curl libffi llvm-18 lld-18))

The curl dependency should be removed, since c3c's optional dependency downloading functionality isn't needed in Guix.
  
Ashvith Shetty March 6, 2025, 8:22 a.m. UTC | #2
Hello,
This is my second attempt at packaging c3-lang (https://github.com/c3lang/c3c). I am planning to refer zig to build all the way from 0.5.1 to the lastest version. In the earlier patches, miniz was unbundled and replaced with the input-provided zlib - however, this time was able to make it work with the input-provided miniz (patch not provided).

1) In the earlier patch I have worked on, I just noticed that I had to substitute ${LLVM_LIBRARY_DIRS}:

--8<---------------cut here---------------start------------->8---
+       (snippet #~(begin
+                    (use-modules (guix build utils))
+                    (substitute* "CMakeLists.txt"
+                      (("\\$\\{LLVM_LIBRARY_DIRS\\}")
+                       (string-append #$lld-18 "/lib/ "
+                                      #$llvm-18 "/lib/")))))))
--8<---------------cut here---------------start------------->8---

However, this seems to me like an improper way to deal with it.

I have a limited understanding of CMake, so please bear with me: Variable ${LLVM_LIBRARY_DIRS} (which I am assuming is a combination of variables including, but not limited to ${LLVM_DIR} and ${LLD_DIR}) seems to include only /gnu/store/z0abzsad781af8qp2wzqq8icwwyxb4ms-llvm-18.1.8/lib/ (${LLVM_DIR}?), but not /gnu/store/62jn91571kx31hqza7c9jzsc3sinkxjr-lld-18.1.8/lib/ (${LLD_DIR}?). When I try printing ${LLD_DIR} in CMakeLists.txt (patch not provided), it appears to be an empty string. Is there anything wrong with the way CMake is configured in c3c?

2) c3c assumes that there exists a compiler or an alias `cc`, but there isn't any such variable in Guix (at least to my knowledge). How do I deal with this issue? Because if not resolved, it also causes the tests to fail. Do I patch cc to gcc/clang/#$(cc-for-target)?

--8<---------------cut here---------------start------------->8---
+               (substitute* '("src/compiler/target.c"
+                              "src/compiler/linker.c")
+                 (("\"cc\"") (string-append "\"" #$(cc-for-target) "\"")))
+               (substitute* "resources/testproject/project.json"
+                 (("\"cc\" : \"cc\",") ""))))
--8<---------------cut here---------------start------------->8---

Or is there a better way to deal with this? By the way, commit 297a6c9 (https://github.com/c3lang/c3c/commit/297a6c93481e2f3b62bf0250750e20549108129d) in v0.6.3 includes support for C3C_LIB and C3C_CC - can this be re-used for earlier patches?

3) Tests in C3C don't run (or maybe I am doing something wrong), so I had to add this instead (this is specific to v0.6.1):
--8<---------------cut here---------------start------------->8---
(replace 'check
                     (lambda* (#:key tests? #:allow-other-keys)
                       (when tests?
                         ;; Compile and run some examples
                         (display "# Compile and run some examples #\n")
                         (with-directory-excursion "../source/resources"
                           (for-each (lambda (file)
                                       (invoke "../../build/c3c" "compile"
                                               file))
                                     '("examples/base64.c3"
                                       "examples/binarydigits.c3"
                                       "examples/brainfk.c3"
                                       "examples/factorial_macro.c3"
                                       "examples/fasta.c3"
                                       "examples/gameoflife.c3"
                                       "examples/hash.c3"
                                       "examples/levenshtein.c3"
                                       "examples/load_world.c3"
                                       "examples/map.c3"
                                       "examples/mandelbrot.c3"
                                       "examples/plus_minus.c3"
                                       "examples/nbodies.c3"
                                       "examples/spectralnorm.c3"
                                       "examples/swap.c3"
                                       "examples/contextfree/boolerr.c3"
                                       "examples/contextfree/dynscope.c3"
                                       "examples/contextfree/guess_number.c3"
                                       "examples/contextfree/multi.c3"
                                       "examples/contextfree/cleanup.c3"))

                           (for-each (lambda (file)
                                       (invoke "../../build/c3c" "compile-run"
                                               file))
                                     '("examples/hello_world_many.c3"
                                       "examples/time.c3"
                                       "examples/fannkuch-redux.c3"
                                       "examples/contextfree/boolerr.c3"
                                       "examples/load_world.c3"
                                       "examples/process.c3"
                                       "examples/ls.c3"
                                       "linux_stack.c3"))

                           (invoke "../../build/c3c" "compile-run"
                                   "--linker=builtin" "linux_stack.c3"))

                         ;; Compile run unit tests
                         (display "# Compile run unit tests #\n")
                         (invoke "./c3c" "compile-test" "../source/test/unit")

                         (with-directory-excursion "../source/resources/testproject"
                           ;; Build testproject
                           (display "# Build testproject #\n")
                           (invoke "../../../build/c3c" "build" "--debug-log")

                           ;; Build testproject direct linker
                           (display "# Build testproject direct linker #\n")
                           (invoke "../../../build/c3c" "build" "--debug-log"
                                   "--linker=builtin"))

                         ;; Run compiler tests
                         (display "# Run compiler tests #\n")
                         (invoke "python3" "../source/test/src/tester.py"
                                 "./c3c" "../source/test/test_suite")))))))
--8<---------------cut here---------------start------------->8---

These tests come from `.github/workflows/main.yml`. I feel like there has to be a better way to do this.

Regards,
Ashvith