unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* setup c/c++ development environment
@ 2021-03-04 16:22 Roy Lemmon
  2021-03-04 19:02 ` Fredrik Salomonsson
  0 siblings, 1 reply; 5+ messages in thread
From: Roy Lemmon @ 2021-03-04 16:22 UTC (permalink / raw)
  To: help-guix

Hi,

I would like to setup a c/c++ development environment on guix. At the moment, I
have used gcc-toolchain to bring in the compiler etc. Are other pieces
necessary ?

Thanks
Roy



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setup c/c++ development environment
  2021-03-04 16:22 Roy Lemmon
@ 2021-03-04 19:02 ` Fredrik Salomonsson
  0 siblings, 0 replies; 5+ messages in thread
From: Fredrik Salomonsson @ 2021-03-04 19:02 UTC (permalink / raw)
  To: Roy Lemmon, help-guix


Hi Roy,

Roy Lemmon <roy@roylemmon.com> writes:

> I would like to setup a c/c++ development environment on guix. At the moment, I
> have used gcc-toolchain to bring in the compiler etc. Are other pieces
> necessary ?

That would be the bare minimum for c/c++. I would recommend using a
build system to build your stuff like GNU autotools[0], cmake[1] or
meson[2].

[0] https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html
[1] https://cmake.org/cmake/help/latest/
[2] https://mesonbuild.com/Tutorial.html

For the ease of use I would recommend meson.

A cool thing I learned from the Guix days last year was from the talk
"Just build it with Guix" by Efraim Flashner [3]. And that was using
guix to do the testing. It works really well.

[3] https://xana.lepiller.eu/guix-days-2020/guix-days-2020-efraim-flashner-build-it-with-guix.mp4

Here is a simplified template of what I use for C++. It uses meson to
build and googletest[4] as the testing framework. But it should be
fairly simple to change to autotools or cmake or another testing
framework, e.g. catch2 [5].

[4] https://github.com/google/googletest/blob/master/docs/primer.md
[5] https://github.com/catchorg/Catch2/blob/devel/docs/why-catch.md#top

-------8<-----------------------------------------------------------------------
(use-modules
  (guix build-system meson)
  (guix gexp)
  (guix git-download)
  (guix packages)
  (guix utils)
  ((guix licenses) #:prefix license:)
  (gnu packages pkg-config)
  (gnu packages check)
  (gnu packages build-tools)
  (gnu packages gcc)
  (ice-9 popen)
  (ice-9 rdelim)
  )

;; From the talk "Just build it with Guix" by Efraim Flashner
;; presented on the Guix days 2020
;; https://guix.gnu.org/en/blog/2020/online-guix-day-announce-2/
(define %source-dir (dirname (current-filename)))

(define %git-commit
  (read-string (open-pipe "git show HEAD | head -1 | cut -d ' ' -f2" OPEN_READ)))

(define (skip-git-and-build-directory file stat)
  "Skip the `.git` and `build` directory when collecting the sources."
  (let ((name (basename file)))
    (not (or (string=? name ".git")
             (string=? name "build")))))

(define-public package-name-here
  (package
    (name "package-name-here")
    (version (git-version "0.1.0"  "HEAD" %git-commit))
    (source (local-file %source-dir
                        #:recursive? #t
                        #:select? skip-git-and-build-directory))
    (build-system meson-build-system)
    (arguments
     `(#:meson ,meson-0.55
       ;; Pass flags to meson
       ;; #:configure-flags '("-Dinstall=true")
       ))
    (native-inputs `(("pkg-config" ,pkg-config)
                     ("googletest" ,googletest)
                     ("gcc" ,gcc-9)))
    (synopsis "Template for building with meson.")
    (description "Simple template for building with meson-0.55 and gcc-9. Using
googletest as the testing framework.")
    ;; (home-page "https://...")
    (license license:gpl3+)
    ))

package-name-here
---------------------------------------------------------------------->8--------

To use it, simply copy the template above into a file called guix.scm,
update the package-name-here and version accordingly and place it at the
root of your project. Note the trailing `package-name-here` at end of
the template, which is there to return a package definition to guix.

Then you can run:

  guix build -f guix.scm

That build your project and run the tests.

If you want to place the guix.scm in a subdirectory, say build-aux.
Change 
  (define %source-dir (dirname (current-filename)))
to
  (define %source-dir (dirname (current-source-directory)))

In the template above.

After that you just run it with

  guix build -f build-aux/guix.scm

I hope that helps.

-- 
s/Fred[re]+i[ck]+/Fredrik/g


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setup c/c++ development environment
       [not found] <GZyuhieLJ3BWP4kae37ZbozD8mpuvUi1Wc2M9bXr9QDDgL6nUQDmi0Nye0j4fSxLn1nGjc3Ply6KPTgSq1aEiop43LAGebaTf7XJQyuekeg=@elenq.tech>
@ 2021-03-11 20:03 ` Fredrik Salomonsson
  2021-03-13 19:29   ` Ekaitz Zarraga
  0 siblings, 1 reply; 5+ messages in thread
From: Fredrik Salomonsson @ 2021-03-11 20:03 UTC (permalink / raw)
  To: Ekaitz Zarraga; +Cc: help-guix


Hi Ekaitz,

CC:ing the rest of the help-guix mailing list, I hope you don't mind.

Ekaitz Zarraga <ekaitz@elenq.tech> writes:

> I have a question with all this you shared.
>
> Is this compiling only the needed parts or it recompiles the whole directory from scratch every time you run `guix build`?

To my knowledge it will recompile everything every time you run
`guix build`.

So this method might be better suited for CI (continuous integration).

But benefit with the `guix.scm` file is that you can also use the same
file to setup the environment you need to build your package.

`guix environment -l guix.scm`
or
`guix environment -l build-aux/guix.scm`

Depending how you have layed out the guix.scm file.

That will use guix to setup the environment needed to build the your
package. And in that shell you can use:

meson build
meson compile -C build
meson test -C build

Or equivalent for other build systems. Which will support partial
builds.

Note that guix might have issues with build generated files for some
build systems when mixing guix environment and guix build. E.g. run
`guix environment`, generate the build files and then run `guix build`.
It seems fine with meson, even when not filtering out the build files.
But I have had issues with GNU autotools and permissions,
`make distclean` before calling `guix build` is a quick workaround. A
better option is probably to filter out those files when collecting the
source.

I hope that answers your question.

-- 
s/Fred[re]+i[ck]+/Fredrik/g


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setup c/c++ development environment
  2021-03-11 20:03 ` setup c/c++ development environment Fredrik Salomonsson
@ 2021-03-13 19:29   ` Ekaitz Zarraga
  2021-03-15  2:25     ` Fredrik Salomonsson
  0 siblings, 1 reply; 5+ messages in thread
From: Ekaitz Zarraga @ 2021-03-13 19:29 UTC (permalink / raw)
  To: Fredrik Salomonsson; +Cc: help-guix

Hi,

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, March 11, 2021 9:03 PM, Fredrik Salomonsson <plattfot@posteo.net> wrote:

>
>
> Hi Ekaitz,
>
> CC:ing the rest of the help-guix mailing list, I hope you don't mind.

Yeah sorry I messed up with the email.

> Ekaitz Zarraga ekaitz@elenq.tech writes:
>
> > I have a question with all this you shared.
> > Is this compiling only the needed parts or it recompiles the whole directory from scratch every time you run `guix build`?
>
> To my knowledge it will recompile everything every time you run
> `guix build`.
>
> So this method might be better suited for CI (continuous integration).
>
> But benefit with the `guix.scm` file is that you can also use the same
> file to setup the environment you need to build your package.
>
> `guix environment -l guix.scm`
> or
> `guix environment -l build-aux/guix.scm`
>
> Depending how you have layed out the guix.scm file.
>
> That will use guix to setup the environment needed to build the your
> package. And in that shell you can use:
>
> meson build
> meson compile -C build
> meson test -C build
>
> Or equivalent for other build systems. Which will support partial
> builds.
>
> Note that guix might have issues with build generated files for some
> build systems when mixing guix environment and guix build. E.g. run
> `guix environment`, generate the build files and then run `guix build`.
> It seems fine with meson, even when not filtering out the build files.
> But I have had issues with GNU autotools and permissions,
> `make distclean` before calling `guix build` is a quick workaround. A
> better option is probably to filter out those files when collecting the
> source.
>
> I hope that answers your question.


So the workflow with guix build is not very good for development but
for CI and stuff like that because you are going to rebuild everything.

Thanks for the explanations.
Ekaitz


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: setup c/c++ development environment
  2021-03-13 19:29   ` Ekaitz Zarraga
@ 2021-03-15  2:25     ` Fredrik Salomonsson
  0 siblings, 0 replies; 5+ messages in thread
From: Fredrik Salomonsson @ 2021-03-15  2:25 UTC (permalink / raw)
  To: Ekaitz Zarraga; +Cc: help-guix


Ekaitz Zarraga <ekaitz@elenq.tech> writes:

> So the workflow with guix build is not very good for development but
> for CI and stuff like that because you are going to rebuild everything.

That pretty much sums it up.

> Thanks for the explanations.

No problem.

-- 
s/Fred[re]+i[ck]+/Fredrik/g


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-15  2:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <GZyuhieLJ3BWP4kae37ZbozD8mpuvUi1Wc2M9bXr9QDDgL6nUQDmi0Nye0j4fSxLn1nGjc3Ply6KPTgSq1aEiop43LAGebaTf7XJQyuekeg=@elenq.tech>
2021-03-11 20:03 ` setup c/c++ development environment Fredrik Salomonsson
2021-03-13 19:29   ` Ekaitz Zarraga
2021-03-15  2:25     ` Fredrik Salomonsson
2021-03-04 16:22 Roy Lemmon
2021-03-04 19:02 ` Fredrik Salomonsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).