Skip to content

Commit

Permalink
Add deb and rpm packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
3XX0 committed Sep 7, 2017
1 parent b48951f commit 7397e1f
Show file tree
Hide file tree
Showing 25 changed files with 443 additions and 85 deletions.
41 changes: 41 additions & 0 deletions Dockerfile.centos
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM centos:7

RUN NVIDIA_GPGKEY_SUM=d1be581509378368edeec8c1eb2958702feedf3bc3d17011adbf24efacce4ab5 && \
curl -fsSL http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/7fa2af80.pub | sed '/^Version/d' > /etc/pki/rpm-gpg/RPM-GPG-KEY-NVIDIA && \
echo "$NVIDIA_GPGKEY_SUM /etc/pki/rpm-gpg/RPM-GPG-KEY-NVIDIA" | sha256sum -c --strict -

COPY mk/cuda.repo /etc/yum.repos.d/cuda.repo

RUN yum install -y \
bzip2 \
cuda-misc-headers-8-0-8.0.61-1 \
cuda-nvml-dev-8-0-8.0.61-1 \
gcc \
git \
libcap-devel \
libseccomp-devel \
m4 \
redhat-lsb-core \
rpm-build \
rpmlint \
which && \
rm -rf /var/cache/yum/*

RUN cd $(mktemp -d) && \
curl -fsSL -O https://mirrors.kernel.org/mageia/distrib/6/x86_64/media/core/release/pmake-1.45-16.mga6.x86_64.rpm && \
curl -fsSL -O https://mirrors.kernel.org/mageia/distrib/6/x86_64/media/core/release/bmake-20161212-1.mga6.x86_64.rpm && \
rpm -i *.rpm && \
rm -rf $PWD

ARG USERSPEC=0:0

WORKDIR /tmp/libnvidia-container
COPY . .
RUN chown -R $USERSPEC $PWD
USER $USERSPEC

RUN make distclean && make -j"$(nproc)"

ENV DIST_DIR /mnt
VOLUME $DIST_DIR
CMD make dist && make rpm
40 changes: 40 additions & 0 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM ubuntu:16.04

RUN NVIDIA_GPGKEY_SUM=d1be581509378368edeec8c1eb2958702feedf3bc3d17011adbf24efacce4ab5 && \
NVIDIA_GPGKEY_FPR=ae09fe4bbd223a84b2ccfce3f60f4b3d7fa2af80 && \
apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub && \
apt-key adv --export --no-emit-version -a $NVIDIA_GPGKEY_FPR | tail -n +5 > cudasign.pub && \
echo "$NVIDIA_GPGKEY_SUM cudasign.pub" | sha256sum -c --strict - && rm cudasign.pub && \
echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/cuda.list

RUN apt-get update && apt-get install -y --no-install-recommends \
bmake \
build-essential \
bzip2 \
ca-certificates \
cuda-misc-headers-8-0=8.0.61-1 \
cuda-nvml-dev-8-0=8.0.61-1 \
curl \
devscripts \
dh-make \
fakeroot \
git \
libcap-dev \
libseccomp-dev \
lintian \
lsb-release \
m4 && \
rm -rf /var/lib/apt/lists/*

ARG USERSPEC=0:0

WORKDIR /tmp/libnvidia-container
COPY . .
RUN chown -R $USERSPEC $PWD
USER $USERSPEC

RUN make distclean && make -j"$(nproc)"

ENV DIST_DIR /mnt
VOLUME $DIST_DIR
CMD make dist && make deb
132 changes: 76 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
#

.PHONY: all utils shared static deps install uninstall dist depsclean mostlyclean clean distclean
.PHONY: all tools shared static deps install uninstall dist depsclean mostlyclean clean distclean
.DEFAULT_GOAL := all

##### Global variables #####
Expand All @@ -12,12 +12,21 @@ WITH_SECCOMP ?= 1

##### Global definitions #####

export CUDA_DIR ?= /usr/local/cuda-8.0
export SRCS_DIR ?= $(CURDIR)/src
export DEPS_DIR ?= $(CURDIR)/deps
export DIST_DIR ?= $(CURDIR)/dist
export MAKE_DIR ?= $(CURDIR)/mk
export DEBUG_DIR ?= $(CURDIR)/.debug
export prefix = /usr/local
export exec_prefix = $(prefix)
export bindir = $(exec_prefix)/bin
export libdir = $(exec_prefix)/lib
export libdbgdir = $(prefix)/lib/debug$(libdir)
export includedir = $(prefix)/include
export pkgconfdir = $(libdir)/pkgconfig

export CUDA_DIR ?= /usr/local/cuda-8.0
export PKG_DIR ?= $(CURDIR)/pkg
export SRCS_DIR ?= $(CURDIR)/src
export DEPS_DIR ?= $(CURDIR)/deps
export DIST_DIR ?= $(CURDIR)/dist
export MAKE_DIR ?= $(CURDIR)/mk
export DEBUG_DIR ?= $(CURDIR)/.debug

include $(MAKE_DIR)/common.mk

Expand Down Expand Up @@ -66,11 +75,15 @@ BIN_SRCS := $(SRCS_DIR)/nvc_cli.c \
$(SRCS_DIR)/utils.c

LIB_SCRIPT = $(SRCS_DIR)/$(LIB_NAME).lds
BIN_SCRIPT = $(SRCS_DIR)/$(BIN_UTILS).lds
BIN_SCRIPT = $(SRCS_DIR)/$(BIN_NAME).lds

##### Target definitions #####

ARCH := x86_64
ifneq ($(wildcard /etc/debian_version),)
ARCH ?= amd64
else
ARCH ?= x86_64
endif
MAJOR := $(call getdef,NVC_MAJOR,$(LIB_INCS))
MINOR := $(call getdef,NVC_MINOR,$(LIB_INCS))
PATCH := $(call getdef,NVC_PATCH,$(LIB_INCS))
Expand All @@ -86,7 +99,7 @@ ifeq ($(PATCH),)
$(error Invalid patch version)
endif

BIN_UTILS := nvidia-container-cli
BIN_NAME := nvidia-container-cli
LIB_NAME := libnvidia-container
LIB_STATIC := $(LIB_NAME).a
LIB_SHARED := $(LIB_NAME).so.$(VERSION)
Expand All @@ -97,49 +110,42 @@ LIB_PKGCFG := $(LIB_NAME).pc
##### Flags definitions #####

# Common flags
ARFLAGS := -rU
CPPFLAGS := -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 $(CPPFLAGS)
CFLAGS := -std=gnu11 -O2 -g -fdata-sections -ffunction-sections -fstack-protector -fno-strict-aliasing -fvisibility=hidden \
-Wall -Wextra -Wcast-align -Wpointer-arith -Wmissing-prototypes -Wnonnull \
-Wwrite-strings -Wlogical-op -Wformat=2 -Wmissing-format-attribute -Winit-self -Wshadow \
-Wstrict-prototypes -Wunreachable-code -Wconversion -Wsign-conversion \
-Wno-unknown-warning-option -Wno-format-extra-args -Wno-gnu-alignof-expression $(CFLAGS)
LDFLAGS := -Wl,-zrelro -Wl,-znow -Wl,-zdefs -Wl,--gc-sections $(LDFLAGS)

# Library flags
_LIB_CPPFLAGS := -DNV_LINUX -isystem $(CUDA_DIR)/include -isystem $(DEPS_DIR)/usr/local/include -include $(BUILD_DEFS)
_LIB_CFLAGS := -fPIC
_LIB_LDFLAGS := -L$(DEPS_DIR)/usr/local/lib -shared -Wl,-soname=$(LIB_SONAME)
_LIB_LDLIBS_STATIC := -l:libelf.a -l:libnvidia-modprobe-utils.a
_LIB_LDLIBS_SHARED := -ldl -lcap
LDLIBS := $(LDLIBS)

# Library flags (recursively expanded to handle target-specific flags)
LIB_CPPFLAGS = -DNV_LINUX -isystem $(CUDA_DIR)/include -isystem $(DEPS_DIR)$(includedir) -include $(BUILD_DEFS)
LIB_CFLAGS = -fPIC
LIB_LDFLAGS = -L$(DEPS_DIR)$(libdir) -shared -Wl,-soname=$(LIB_SONAME)
LIB_LDLIBS_STATIC = -l:libelf.a -l:libnvidia-modprobe-utils.a
LIB_LDLIBS_SHARED = -ldl -lcap
ifeq ($(WITH_TIRPC), 1)
_LIB_CPPFLAGS += -isystem $(DEPS_DIR)/usr/local/include/tirpc -DWITH_TIRPC
_LIB_LDLIBS_STATIC += -l:libtirpc.a
_LIB_LDLIBS_SHARED += -lpthread
LIB_CPPFLAGS += -isystem $(DEPS_DIR)$(includedir)/tirpc -DWITH_TIRPC
LIB_LDLIBS_STATIC += -l:libtirpc.a
LIB_LDLIBS_SHARED += -lpthread
endif
ifeq ($(WITH_SECCOMP), 1)
_LIB_CPPFLAGS += -DWITH_SECCOMP
_LIB_LDLIBS_SHARED += -lseccomp
LIB_CPPFLAGS += -DWITH_SECCOMP
LIB_LDLIBS_SHARED += -lseccomp
endif
_LIB_LDLIBS := $(_LIB_LDLIBS_STATIC) $(_LIB_LDLIBS_SHARED)
# Library flags + common flags (recursively expanded to handle target-specific flags)
LIB_CPPFLAGS = $(_LIB_CPPFLAGS) $(CPPFLAGS)
LIB_CFLAGS = $(_LIB_CFLAGS) $(CFLAGS)
LIB_LDFLAGS = $(_LIB_LDFLAGS) $(LDFLAGS)
LIB_LDLIBS_STATIC = $(_LIB_LDLIBS_STATIC)
LIB_LDLIBS_SHARED = $(_LIB_LDLIBS_SHARED) $(LDLIBS)
LIB_LDLIBS = $(_LIB_LDLIBS) $(LDLIBS)

# Binary flags
_BIN_CPPFLAGS := -include $(BUILD_DEFS)
_BIN_CFLAGS := -fPIE -flto
_BIN_LDFLAGS := -L. -pie
_BIN_LDLIBS := -l:$(LIB_SHARED) -lcap
# Binary flags + common flags (recursively expanded to handle target-specific flags)
BIN_CPPFLAGS = $(_BIN_CPPFLAGS) $(CPPFLAGS)
BIN_CFLAGS = $(_BIN_CFLAGS) $(CFLAGS)
BIN_LDFLAGS = $(_BIN_LDFLAGS) $(LDFLAGS)
BIN_LDLIBS = $(_BIN_LDLIBS) $(LDLIBS)
LIB_CPPFLAGS += $(CPPFLAGS)
LIB_CFLAGS += $(CFLAGS)
LIB_LDFLAGS += $(LDFLAGS)
LIB_LDLIBS_STATIC +=
LIB_LDLIBS_SHARED += $(LDLIBS)
LIB_LDLIBS = $(LIB_LDLIBS_STATIC) $(LIB_LDLIBS_SHARED)

# Binary flags (recursively expanded to handle target-specific flags)
BIN_CPPFLAGS = -include $(BUILD_DEFS) $(CPPFLAGS)
BIN_CFLAGS = -fPIE -flto $(CFLAGS)
BIN_LDFLAGS = -L. -pie $(LDFLAGS)
BIN_LDLIBS = -l:$(LIB_SHARED) -lcap $(LDLIBS)

$(word 1,$(LIB_RPC_SRCS)): RPCGENFLAGS=-h
$(word 2,$(LIB_RPC_SRCS)): RPCGENFLAGS=-c
Expand Down Expand Up @@ -181,33 +187,31 @@ $(LIB_SHARED): $(LIB_OBJS)

$(LIB_STATIC_OBJ): $(LIB_OBJS)
# FIXME Handle user-defined LDFLAGS and LDLIBS
$(LD) -d -r --exclude-libs ALL -L$(DEPS_DIR)/usr/local/lib $(OUTPUT_OPTION) $^ $(LIB_LDLIBS_STATIC)
$(LD) -d -r --exclude-libs ALL -L$(DEPS_DIR)$(libdir) $(OUTPUT_OPTION) $^ $(LIB_LDLIBS_STATIC)
$(OBJCPY) --localize-hidden $@
$(STRIP) --strip-unneeded -R .comment $@

$(BIN_UTILS): $(BIN_OBJS)
$(BIN_NAME): $(BIN_OBJS)
$(CC) $(BIN_CFLAGS) $(BIN_CPPFLAGS) $(BIN_LDFLAGS) $(OUTPUT_OPTION) $^ $(BIN_SCRIPT) $(BIN_LDLIBS)
$(STRIP) --strip-unneeded -R .comment $@

##### Public rules #####

all: release
all: CPPFLAGS += -DNDEBUG
all: shared static tools

debug: CFLAGS += -pedantic -fsanitize=undefined -fno-omit-frame-pointer -fno-common
debug: LDLIBS += -lubsan
debug: STRIP := @echo skipping: strip
debug: shared static utils

release: CPPFLAGS += -DNDEBUG
release: shared static utils
debug: shared static tools

utils: $(BIN_UTILS)
tools: $(BIN_NAME)

shared: $(LIB_SHARED)

static: $(LIB_STATIC)($(LIB_STATIC_OBJ))

deps: export DESTDIR=$(DEPS_DIR)
deps: export DESTDIR:=$(DEPS_DIR)
deps: $(LIB_RPC_SRCS) $(BUILD_DEFS)
$(MKDIR) -p $(DEPS_DIR)
$(MAKE) -f $(MAKE_DIR)/elftoolchain.mk install
Expand All @@ -228,9 +232,9 @@ install: all
# Install debugging symbols
$(INSTALL) -m 644 $(DEBUG_DIR)/$(LIB_SONAME) $(DESTDIR)$(libdbgdir)
# Install configuration files
$(M4) -D'$$VERSION=$(strip $(VERSION))' -D'$$PRIVATE_LIBS=$(strip $(LIB_LDLIBS_SHARED))' $(MAKE_DIR)/$(LIB_PKGCFG).m4 > $(DESTDIR)$(pkgconfdir)/$(LIB_PKGCFG)
$(MAKE_DIR)/$(LIB_PKGCFG).in "$(strip $(VERSION))" "$(strip $(LIB_LDLIBS_SHARED))" > $(DESTDIR)$(pkgconfdir)/$(LIB_PKGCFG)
# Install binary files
$(INSTALL) -m 755 $(BIN_UTILS) $(DESTDIR)$(bindir)
$(INSTALL) -m 755 $(BIN_NAME) $(DESTDIR)$(bindir)

uninstall:
# Uninstall header files
Expand All @@ -242,9 +246,9 @@ uninstall:
# Uninstall configuration files
$(RM) $(DESTDIR)$(pkgconfdir)/$(LIB_PKGCFG)
# Uninstall binary files
$(RM) $(DESTDIR)$(bindir)/$(BIN_UTILS)
$(RM) $(DESTDIR)$(bindir)/$(BIN_NAME)

dist: DESTDIR=$(DIST_DIR)/$(LIB_NAME)_$(VERSION)
dist: DESTDIR:=$(DIST_DIR)/$(LIB_NAME)_$(VERSION)$(addprefix -,$(TAG))
dist: install
$(TAR) -C $(dir $(DESTDIR)) -caf $(DESTDIR)_$(ARCH).tar.xz $(notdir $(DESTDIR))
$(RM) -r $(DESTDIR)
Expand All @@ -264,4 +268,20 @@ clean: mostlyclean depsclean

distclean: clean
$(RM) -r $(DEPS_DIR) $(DIST_DIR) $(DEBUG_DIR)
$(RM) $(LIB_RPC_SRCS) $(LIB_STATIC) $(LIB_SHARED) $(BIN_UTILS)
$(RM) $(LIB_RPC_SRCS) $(LIB_STATIC) $(LIB_SHARED) $(BIN_NAME)

deb: DESTDIR:=$(DIST_DIR)/$(LIB_NAME)_$(VERSION)_$(ARCH)
deb: prefix:=/usr
deb: libdir:=/usr/lib/@DEB_HOST_MULTIARCH@
deb: install
$(CP) -T $(PKG_DIR)/deb $(DESTDIR)/debian
cd $(DESTDIR) && debuild -eDISTRIB -eSECTION --dpkg-buildpackage-hook='debian/prepare %v' -a $(ARCH) -us -uc -B
cd $(DESTDIR) && debuild clean

rpm: DESTDIR:=$(DIST_DIR)/$(LIB_NAME)_$(VERSION)_$(ARCH)
rpm: all
$(CP) -T $(PKG_DIR)/rpm $(DESTDIR)
$(LN) -nsf $(CURDIR) $(DESTDIR)/BUILD
$(MKDIR) -p $(DESTDIR)/RPMS && $(LN) -nsf $(DIST_DIR) $(DESTDIR)/RPMS/$(ARCH)
cd $(DESTDIR) && rpmbuild --clean --target=$(ARCH) -bb -D"_topdir $(DESTDIR)" -D"_version $(VERSION)" -D"_tag $(TAG)" -D"_major $(MAJOR)" SPECS/*
-cd $(DESTDIR) && rpmlint RPMS/*
10 changes: 1 addition & 9 deletions mk/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@
# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
#

export prefix ?= /usr/local
export exec_prefix ?= $(prefix)
export bindir ?= $(exec_prefix)/bin
export libdir ?= $(exec_prefix)/lib
export libdbgdir ?= $(libdir)/debug/$(libdir)
export includedir ?= $(prefix)/include
export pkgconfdir ?= $(libdir)/pkgconfig

MV ?= mv -f
CP ?= cp -a
LN ?= ln
M4 ?= m4
TAR ?= tar
CURL ?= curl
MKDIR ?= mkdir
Expand Down
6 changes: 6 additions & 0 deletions mk/cuda.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[cuda]
name=cuda
baseurl=http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-NVIDIA
1 change: 1 addition & 0 deletions mk/elftoolchain.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include $(MAKE_DIR)/common.mk

export MKSHARE := no
export MKPROFILE := no
export LORDER := echo
export INSTALL := $(INSTALL) -D
export BINOWN := $(shell id -u)
export BINGRP := $(shell id -g)
Expand Down
20 changes: 20 additions & 0 deletions mk/libnvidia-container.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/sh

set -u

VERSION="$1"
PRIVATE_LIBS="$2"

cat <<EOF
prefix=$prefix
exec_prefix=$exec_prefix
libdir=$libdir
includedir=$includedir
Name: libnvidia-container
Description: NVIDIA container library
Version: $VERSION
Libs: -L\${libdir} -lnvidia-container
Libs.private: $PRIVATE_LIBS
Cflags: -I\${includedir}
EOF
19 changes: 0 additions & 19 deletions mk/libnvidia-container.pc.m4

This file was deleted.

2 changes: 1 addition & 1 deletion mk/libtirpc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $(SRCS_DIR)/.download_stamp:
@touch $@

$(SRCS_DIR)/.build_stamp: $(SRCS_DIR)/.download_stamp
cd $(SRCS_DIR) && ./configure --prefix=$(DESTDIR)/usr/local --enable-static --disable-shared --disable-gssapi --with-pic
cd $(SRCS_DIR) && ./configure --prefix=$(DESTDIR)$(prefix) --enable-static --disable-shared --disable-gssapi --with-pic
$(MAKE) -C $(SRCS_DIR)
@touch $@

Expand Down
5 changes: 5 additions & 0 deletions pkg/deb/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
libnvidia-container (1.0.0~alpha.1-1) UNRELEASED; urgency=medium

* Initial release

-- NVIDIA CORPORATION <[email protected]> Tue, 05 Sep 2017 14:31:33 -0700
Loading

0 comments on commit 7397e1f

Please sign in to comment.