Header only library for writing build recipes in C.

Overview

nobuild

Header only library for writing build recipes in C.

Main idea

The idea is that you should not need anything but a C compiler to build a C project. No make, no cmake, no shell, no cmd, no PowerShell etc. Only C compiler. So with the C compiler you bootstrap your build system and then you use the build system to build everything else.

Try it out right here:

$ cc ./nobuild.c -o nobuild
$ ./nobuild

Explore nobuild.c file and the examples folder to learn more.

How to use the library in your own project

Keep in mind that nobuild.h is an stb-style header-only library. That means that just including it does not include the implementations of the functions. You have to define NOBUILD_IMPLEMENTATION macro before the include. See our nobuild.c for an example.

  1. Copy nobuild.h to your project
  2. Create nobuild.c in your project with the build recipe. See our nobuild.c for an example.
  3. Bootstrap the nobuild executable:
    • $ cc nobuild.c -o nobuild on POSIX systems
    • $ cl.exe nobuild.c on Windows with MSVC
  4. Run the build: $ ./nobuild

API Conventions

  • Functions from nobuild.h that start with nobuild__ (double underscore) are private to the library and should not be relied upon. They can be changed in any release without a warning.
Issues
  • I get this error when trying this with unmodified nobuild.c and nobuild.h

    I get this error when trying this with unmodified nobuild.c and nobuild.h

    cl.exe nobuild.c Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26730 for x64 Copyright (C) Microsoft Corporation. All rights reserved.

    nobuild.c Microsoft (R) Incremental Linker Version 14.15.26730.0 Copyright (C) Microsoft Corporation. All rights reserved.

    /out:nobuild.exe nobuild.obj LINK : fatal error LNK1561: entry point must be defined

    Windows 10 I am no C expert .. (thats why I wanted to try this ...)

    opened by frunjik 4
  • Add printf format attribute warning to LOG, WARN, and friends

    Add printf format attribute warning to LOG, WARN, and friends

    Add __attribute__((format(printf, ...))) to LOG, WARN, ERRO, and PANIC. Should prevent things like #24 from occurring in the future. Also, fix one of the bugs that was found by using this attribute.

    opened by zhiayang 1
  • Segmentation Fault deep in libc on FreeBSD 13.0 arm64

    Segmentation Fault deep in libc on FreeBSD 13.0 arm64

    While building bm:

    [[email protected] ~/src/bm]$ uname -a
    FreeBSD henricus.herrhotzenplotz.geek 13.0-RELEASE FreeBSD 13.0-RELEASE #0 releng/13.0-n244733-ea31abc261f: Fri Apr  9 06:06:55 UTC 2021     [email protected]:/usr/obj/usr/src/arm64.aarch64/sys/GENERIC  arm64
    [[email protected] ~/src/bm]$
    [[email protected] ~/src/bm]$ $CC $CFLAGS -o nobuild nobuild.c
    [[email protected] ~/src/bm]$ file nobuild
    nobuild: ELF 64-bit LSB executable, ARM aarch64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 13.0 (1300139), FreeBSD-style, with debug_info, not stripped
    [[email protected] ~/src/bm]$ ./nobuild test
    [INFO] MKDIRS: build/library
    [INFO] CMD: cc -Wall -Wextra -Wswitch-enum -Wmissing-prototypes -Wconversion -Wno-missing-braces -pedantic -fno-strict-aliasing -ggdb -std=c11 -c src/library/arena.c -o build/library/arena.o
    
    ....<snip>....
    
    [INFO] RM: build/toolchain
    [WARN] [3] + Segmentation fault - core dumped ./nobuild test
    [[email protected] ~/src/bm]$
    

    Here, strlen was called inside vfprintf since a %s format was provided in the WARN macro. However, it was missing a corresponding parameter, so strlen tried to dereference a garbage pointer and caused the expectable SIGSEGV.

    This patch adds the missing argument to %s.

    At the same time, we may want to update the nobuild dependency in bm itself.

    opened by herrhotzenplotz 1
  • there is no way to redirect the output of CMD to a file

    there is no way to redirect the output of CMD to a file

    PIPE(CMD("cat"),
         CMD("sort", "-n"));
    
    PIPE(IN("input.txt"),
         CMD("cat"),
         CMD("sort", "-n"));
    
    PIPE(CMD("cat"),
         CMD("sort", "-n"),
         OUT("output.txt"));
    
    PIPE(IN("input.txt"),
         CMD("cat"),
         CMD("sort", "-n"),
         OUT("output.txt"));
    
    opened by rexim 0
  • Potential memory issue in `PIPE`

    Potential memory issue in `PIPE`

    Please correct me if I'm wrong, but I think you have a memory issue. In https://github.com/tsoding/nobuild/blob/47e280e01a2ea253299660cb4bb619fb686a690a/nobuild.h#L752-L762 you de-reference the input fds, but in https://github.com/tsoding/nobuild/blob/47e280e01a2ea253299660cb4bb619fb686a690a/nobuild.h#L863 you create that on the stack, once for all of them. You overwrite them in each iteration. But afaik you are not guaranteed that the child runs and de-references those pointers before you get to the next command in the loop.

    opened by cpiber 0
  • FOREACH_FILE_IN_DIR potentially invalidates the name of the file on each iteration

    FOREACH_FILE_IN_DIR potentially invalidates the name of the file on each iteration

    Which might not be what the user actually want.

    Consider this use case.

    Cstr_Array line = cstr_array_make(cxx, CFLAGS_EXE, NULL);
    FOREACH_FILE_IN_DIR(file, ".",
    {
        if (ENDS_WITH(file, ".o"))
        {
            line = cstr_array_append(line, file);
        }
    });
    Cmd cmd = {
        .line = line
    };
    cmd_run_sync(cmd);
    

    Here we actually need to strdup the string before pushing it to the list:

    --- test.c    2021-07-30 03:22:06.603302201 +0700
    +++ test2.c    2021-07-30 03:22:22.127512662 +0700
    @@ -2,7 +2,7 @@
     FOREACH_FILE_IN_DIR(file, ".", {
         if (ENDS_WITH(file, ".o"))
         {
    -        line = cstr_array_append(line, file);
    +        line = cstr_array_append(line, strdup(file));
         }
     });
     Cmd cmd = {
    

    We need to think how we wanna approach this usability issue. Maybe do that strdup for the user?

    (Found by @Ciremun)

    opened by rexim 0
  • GO_REBUILD_URSELF only works when running with `nobuild.exe` on Windows, not `nobuild`

    GO_REBUILD_URSELF only works when running with `nobuild.exe` on Windows, not `nobuild`

    On Windows, after bootstrapping nobuild, GO_REBUILD_URSELF expects the full filepath of nobuild.exe to be run from the terminal. Executing with just nobuild causes [ERRO] Could not open file nobuild.

    opened by mimhufford 0
Releases(v0.2.0)
  • v0.2.0(Jan 29, 2021)

    • Introduced ENDS_WITH(str, postfix) function that checks if str ends with postfix.
    • Introduced IS_DIR(path) function that checks if pathis a directory.
    • Introduced RM(path) function that removes the specified path. It does not care if the path is file or directory, it just removes everything recursive every time.
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Jan 28, 2021)

    • Introduced logging functions INFO(fmt, ...), WARN(fmt, ...), ERRO(fmt, ...).
    • Introduced API conventions. Functions that start with nobuild__ (double underscore) are private to the library and should not be relied upon. They can be changed in any release without a warning.

    Deprecations

    All the deprecated functions and macros will be removed in the next major release.

    • remove_ext(path) is deprecated. Use NOEXT(path) instead.
    • CONCAT_SEP(sep, ...) is deprecated. Use JOIN(sep, ...) instead.
    • concat_sep_impl(sep, ...) is deprecated. Use JOIN(sep, ...) instead.
    Source code(tar.gz)
    Source code(zip)
Owner
Tsoding
Recreational Programming
Tsoding
A C++ header-only HTTP/HTTPS server and client library

cpp-httplib A C++11 single-file header-only cross platform HTTP/HTTPS library. It's extremely easy to setup. Just include the httplib.h file in your c

null 7.2k Jun 24, 2022
Brynet - Header Only Cross platform high performance TCP network library using C++ 11.

Brynet Header Only Cross platform high performance TCP network library using C++ 11. Build status Windows : Linux/MacOS : Features Header only Cross p

IronsDu 848 Jun 27, 2022
Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!

Do you have a question that doesn't require you to open an issue? Join the gitter channel. If you use uvw and you want to say thanks or support the pr

Michele Caini 1.5k Jun 24, 2022
Header-only C++14 library for getting network addresses associated with network interface without name lookups on Windows, macOS, Linux, and FreeBSD

NetIF Get addresses associated with network interfaces on a system without using name lookups. Header-only, requires C++14. Usage Add the header file

GMLC-TDC 9 Feb 4, 2022
Lightweight, header-only, Boost-based socket pool library

Stream-client This is a lightweight, header-only, Boost-based library providing client-side network primitives to easily organize and implement data t

Tinkoff.ru 12 May 27, 2022
🥡 Simple header-only RSP server library

librspd Simple header-only, arch-agnostic, RSP server library. What is it about, already ? See https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protoc

Nicolas Sauzede 2 Nov 21, 2021
Netif - Header-only C++14 library for getting network addresses associated with network interface without name lookups on Windows, macOS, Linux, and FreeBSD

NetIF Get addresses associated with network interfaces on a system without using name lookups. Header-only, requires C++14. Usage Add the header file

GMLC-TDC 9 Feb 4, 2022
Asynchronous, Header-only C++ HTTP-over-(TCP|UNIX Socket|STDIO) Library

CXXHTTP A C++ library implementing an asynchronous HTTP server and client. To clone this library, make sure you also clone the submodules. The --recur

null 25 Mar 19, 2021
modern c++(c++17), cross-platform, header-only, easy to use http framework

cinatra--一个高效易用的c++ http框架 English | 中文 目录 使用cinatra常见问题汇总(FAQ) cinatra简介 如何使用 快速示例 性能测试 注意事项 roadmap 联系方式 cinatra简介 cinatra是一个高性能易用的http框架,它是用modern

qicosmos 1.3k Jun 21, 2022
Header-only C++ binding for libzmq

Introduction & Design Goals cppzmq is a C++ binding for libzmq. It has the following design goals: cppzmq maps the libzmq C API to C++ concepts. In pa

The ZeroMQ project 1.3k Jun 19, 2022
This repo contains Direct3D 9, Direct3D 10, a few Direct3D 11, and DirectSound C++ samples from the legacy DirectX SDK updated to build using the Windows 10 SDK and the Microsoft.DXSDK.D3DX NuGet package

DirectX SDK Legacy Samples This repo contains Direct3D 9, Direct3D 10, a few Direct3D 11, and DirectSound samples that originally shipped in the legac

Chuck Walbourn 33 Jun 21, 2022
Build a redis client by cpp:)

Redix A light redis client implement by c++. Develop Environment cmake:3.16.3 g++:9.3.0 os:ubuntu 20.04.01 reids:5.0.7 Welcome to see my talk. Benchma

null 3 Apr 15, 2022
Nin - It's metal to my ears. Build system in Go.

nin An experimental fork of ninja translated in Go. Currently a toy. Are you serious? Yeah. Marc-Antoine, isn't it a stupid idea? Yeah. When Google wa

M-A 6 May 26, 2022
Automated upstream mirror for bpftool stand-alone build.

bpftool This is a mirror of bpf-next Linux source tree's tools/bpf/bpftool directory, plus its few dependencies from under kernel/bpf/, and its suppor

null 43 Jun 24, 2022
An extensible, cross-platform, single-header C/C++ OpenGL loader library.

Simple OpenGL Loader An extensible, cross-platform, single-header C/C++ OpenGL loader library. Usage For Windows Win32 or Linux X11 applications, the

Tarek Sherif 78 May 30, 2022
single header C(99) library to implement client-server network code for games

single header C(99) library to implement client-server network code for games

Nathan 217 Jun 16, 2022
A single-header socket library for both Linux and Windows

COMS What is COMS? COMS is a single-header library designed to be simple to use. It supports TCP and UDP, Server and Client. Available for Windows and

null 5 Dec 23, 2021
Minimalistic socket library inspired by Asio/Boost Asio, implemented in 1 single header file

cz-spas czspas (Small Portable Asynchronous Sockets) is minimalistic socket library inspired by Asio/Boost Asio, implemented in 1 single header file.

Rui Figueira 25 Jun 12, 2022
web server that will print hello world on the screen only for linux users

a simple http server side lib only for linux users Note: This lib is currently under development you can check the source code and even use it but dn'

notaweeb 11 Mar 14, 2021