Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Rust #262

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
__pycache__/
build/
dist/
target
dumb-init
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dumb-init
62 changes: 62 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'dumb-init'",
"cargo": {
"args": [
"build",
"--bin=dumb-init",
"--package=dumb-init"
],
"filter": {
"name": "dumb-init",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'dumb-init'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=dumb-init",
"--package=dumb-init"
],
"filter": {
"name": "dumb-init",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"name": "Python: Setup.py",
"type": "python",
"request": "launch",
"program": "setup.py",
"console": "integratedTerminal",
"justMyCode": false,
"args": [
"bdist"
]
},
{
"name": "Python: Attach using Process Id",
"type": "python",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
29 changes: 29 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"command": "build",
"problemMatcher": [
"$rustc"
],
"group": "build",
"label": "rust: cargo build",
"presentation": {
"clear": true
}
},
{
"type": "cargo",
"command": "check",
"problemMatcher": [
"$rustc"
],
"group": "build",
"label": "rust: cargo check",
"presentation": {
"clear": true
}
}
]
}
122 changes: 122 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "dumb-init"
version = "1.2.5"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libc = "0.2.105"
ioctl-rs = "0.2.0"
nix = "0.23.0"
regex = "1.5.4"
getopts = "0.2.21"
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ RUN : \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
curl \
debcargo \
devscripts \
equivs \
lintian \
python3-distutils \
python3-setuptools \
python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
&& curl https://sh.rustup.rs -sSf | sh -s -- -y
WORKDIR /tmp/mnt

COPY debian/control /control
Expand Down
5 changes: 3 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include dumb-init.c
include Cargo.toml
include Cargo.lock
recursive-include src *
include VERSION
include VERSION.h
17 changes: 8 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
SHELL=bash
CFLAGS=-std=gnu99 -static -s -Wall -Werror -O3
CARGOFLAGS=--release

TEST_PACKAGE_DEPS := build-essential python python-pip procps python-dev python-setuptools

DOCKER_RUN_TEST := docker run -v $(PWD):/mnt:ro
VERSION = $(shell cat VERSION)

.PHONY: build
build: VERSION.h
$(CC) $(CFLAGS) -o dumb-init dumb-init.c
build: cargo-toml-version
cargo build $(CARGOFLAGS) $(TARGET)

VERSION.h: VERSION
echo '// THIS FILE IS AUTOMATICALLY GENERATED' > VERSION.h
echo '// Run `make VERSION.h` to update it after modifying VERSION.' >> VERSION.h
xxd -i VERSION >> VERSION.h
.PHONY: cargo-toml-version
cargo-toml-version: VERSION
sed -i -z 's/name = "dumb-init"\nversion = "[0-9]*\.[0-9]*\.[0-9]*"/name = "dumb-init"\nversion = "$(VERSION)"/' Cargo.toml

.PHONY: clean
clean: clean-tox
rm -rf dumb-init dist/ *.deb
rm -rf target/ dist/ *.deb

.PHONY: clean-tox
clean-tox:
Expand All @@ -33,7 +32,7 @@ release: python-dists
python-dists: python-dists-x86_64 python-dists-aarch64 python-dists-ppc64le python-dists-s390x

.PHONY: python-dists-%
python-dists-%: VERSION.h
python-dists-%: cargo-toml-version
python setup.py sdist
docker run \
--user $$(id -u):$$(id -g) \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Statically compiled dumb-init is over 700KB due to glibc, but musl is now an
option. On Debian/Ubuntu `apt-get install musl-tools` to install the source and
wrappers, then just:

$ CC=musl-gcc make
$ TARGET=x86_64-unknown-linux-musl make

When statically compiled with musl the binary size is around 20KB.

Expand Down
6 changes: 0 additions & 6 deletions VERSION.h

This file was deleted.

4 changes: 4 additions & 0 deletions ci/docker-python-test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ set -euo pipefail

cd /mnt

PATH=~/.cargo/bin:$PATH

# requirements first for setup.py.
pip3 install -r requirements-dev.txt
python3 setup.py clean
python3 setup.py sdist
pip3 install -vv dist/*.tar.gz
Expand Down
8 changes: 5 additions & 3 deletions ci/gcov-build
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
envbindir="$1"
cc -c dumb-init.c -o dumb-init.o -g --coverage
cc dumb-init.o -o "${envbindir}/dumb-init" -g --coverage
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
export RUSTDOCFLAGS="-Cpanic=abort"

cargo +nightly build
Loading