commit 7e68a5d0527a3766aaa202e4bc72dcf36c01436b from: Murilo Ijanc date: Fri Apr 24 20:03:59 2026 UTC add examples/ and expose VERSION const Populate VERSION from the HTTP_VERSION environment variable which make already passes to rustc, so downstream crates can print or log the library version without a second source of truth. Add examples/hello.rs, a minimal binary that links against the rlib and prints the version. A generic Makefile pattern rule builds any file under examples/ into build/ex-, driven by the new examples target. commit - 2625e3b992c23567e34d9dc1be8c364cd637a2ae commit + 7e68a5d0527a3766aaa202e4bc72dcf36c01436b blob - 543c1daefddb255476d8b3868e27583d42788de9 blob + 91af43266592c3382ac6072c36751037b6cbecb0 --- Makefile +++ Makefile @@ -23,13 +23,16 @@ SRC = http.rs LIB = $(BUILD)/libhttp.rlib TEST = $(BUILD)/http-test +EXAMPLE_SRCS = $(wildcard examples/*.rs) +EXAMPLES = $(EXAMPLE_SRCS:examples/%.rs=$(BUILD)/ex-%) + CLIPPY ?= $(shell rustup which clippy-driver 2>/dev/null) RUSTFMT ?= $(shell rustup which rustfmt 2>/dev/null) RUSTDOC ?= $(shell rustup which rustdoc 2>/dev/null || which rustdoc) DOC = $(BUILD)/doc/http/index.html -.PHONY: all clean test fmt-check clippy ci doc +.PHONY: all clean test fmt-check clippy ci doc examples all: $(LIB) @@ -66,5 +69,13 @@ $(DOC): $(SRC) doc: $(DOC) +$(BUILD)/ex-%: examples/%.rs $(LIB) + mkdir -p $(BUILD) + HTTP_VERSION=$(VERSION) $(RUSTC) --edition 2024 \ + --crate-name $* --extern http=$(LIB) -L $(BUILD) \ + $(RUSTFLAGS) -o $@ $< + +examples: $(EXAMPLES) + clean: rm -rf $(BUILD) blob - 1eea2e11450dfca287e834eb2402ceec265f3da1 blob + a8a2b033e1f69886ce6871a74a6bcc2ddf8d34af --- http.rs +++ http.rs @@ -18,3 +18,6 @@ //! Minimal HTTP/1.0 and HTTP/1.1 library. //! //! Conforms to RFC 1945 (HTTP/1.0) and RFC 2616 (HTTP/1.1). + +/// Library version, injected at build time from `HTTP_VERSION`. +pub const VERSION: &str = env!("HTTP_VERSION"); blob - /dev/null blob + 4892e65bd93d77dad9563a42ab33071219c1415f (mode 644) --- /dev/null +++ examples/hello.rs @@ -0,0 +1,22 @@ +// vim: set tw=79 cc=80 ts=4 sw=4 sts=4 et : +// +// Copyright (c) 2026 Murilo Ijanc' +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// + +//! Minimal example that links against the http library. + +fn main() { + println!("http v{}", http::VERSION); +}