aboutsummaryrefslogtreecommitdiff
path: root/src/build.h
blob: dc684053527ac7f455eaf1753b0fa2d2eda98343 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* embed_build.h - build identity for the embed and embed-server front-ends.
 *
 * The real values come from the Makefile's VERSION_CFLAGS at compile time; the
 * fallbacks below apply when those flags are absent. Front-end only: the
 * inference library does not use these. */
#ifndef EMBED_BUILD_H
#define EMBED_BUILD_H

#include <stdio.h>
#include <string.h>

#ifndef EMBED_VERSION
#define EMBED_VERSION "development"
#endif
#ifndef EMBED_BUILD_COMMIT
#define EMBED_BUILD_COMMIT "unknown"
#endif
#ifndef EMBED_BUILD_DATE
#define EMBED_BUILD_DATE "unknown"
#endif
#ifndef EMBED_BUILD_OS
#define EMBED_BUILD_OS "unknown"
#endif
#ifndef EMBED_BUILD_ARCH
#define EMBED_BUILD_ARCH "unknown"
#endif

/* Backend label for --build-info, selected by the same macro that picks the
 * compiled inference path. */
#if defined(USE_MLX)
#define EMBED_BUILD_BACKENDS "accelerate,mlx"
#elif defined(USE_CUDA)
#define EMBED_BUILD_BACKENDS "openblas,cuda"
#elif defined(__APPLE__)
#define EMBED_BUILD_BACKENDS "accelerate"
#else
#define EMBED_BUILD_BACKENDS "openblas"
#endif

/* Program name with any leading directory removed. */
static inline const char *embed_prog_name(const char *argv0)
{
    const char *slash = strrchr(argv0, '/');
    return slash ? slash + 1 : argv0;
}

static inline void embed_print_version(const char *prog)
{
    printf("%s %s (%s/%s)\n", prog, EMBED_VERSION,
           EMBED_BUILD_OS, EMBED_BUILD_ARCH);
}

static inline void embed_print_build_info(const char *prog)
{
    embed_print_version(prog);
    printf("backend:  %s\n"
           "compiler: %s\n"
           "built:    %s\n"
           "commit:   %s\n",
           EMBED_BUILD_BACKENDS, __VERSION__,
           EMBED_BUILD_DATE, EMBED_BUILD_COMMIT);
}

#endif /* EMBED_BUILD_H */