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

Static amalgamated build of lighttpd #9

Open
wants to merge 4 commits into
base: main
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
40 changes: 37 additions & 3 deletions amalgamate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,40 @@ function amalgamatedPath(extension) {
return pathLib.resolve(`lighttpd.amalgamated.${extension}`);
}

// Definitions that conflict between multiple module files,
// so we rename them to a per-module name using #define
const PER_FILE_ALIASES = [
"cpk",
"plugin_config",
"plugin_data",
"handler_ctx",
"handler_ctx_init",
"handler_ctx_free",
"mkdir_recursive",
"proxy_forwarded_t",
"PROXY_FORWARDED_NONE",
"PROXY_FORWARDED_FOR",
"PROXY_FORWARDED_PROTO",
"PROXY_FORWARDED_HOST",
"PROXY_FORWARDED_BY",
"PROXY_FORWARDED_REMOTE_USER",
];

function includePath(path) {
const file = pathLib.basename(path, '.c');
let lines = [];
if (file.startsWith('mod_')) {
for (const alias of PER_FILE_ALIASES) {
lines.push(`#undef ${alias}`);
lines.push(`#define ${alias} ${file}_${alias}`);
}
}
lines.push(`#include "${path}"`);
return lines.join("\n");
}

const commands = JSON.parse((await fsp.readFile("compile_commands.json")).toString())
.filter(e => pathLib.relative(".", e.directory) === "build")
.filter(e => pathLib.relative(".", e.directory) === "src")
.filter(e => ![
// These are for other binaries and so have their own `main`s, which conflict.
"lemon.c",
Expand All @@ -22,7 +54,7 @@ const includes = [
"src/algo_xxhash.c",
...commands.map(e => pathLib.relative(".", e.file))
]
.map(path => `#include "${path}"`)
.map(includePath)
.join("\n")
;

Expand All @@ -32,6 +64,8 @@ const flags = [...new Set(
["cc"].length, // Slice off the compiler invocation (not a flag).
-["-o", "obj", "-c", "src"].length, // Slice off the file-specific args that aren't flags.
)
// Single-quote every flag because some of them might contain quotes
.map(flag => `'${flag}'`)
)
)];

Expand All @@ -42,7 +76,7 @@ const directory = directories[0];
const amalgamated = {
exe: {
directory,
arguments: ["cc", ...flags, "-o", amalgamatedPath("exe"), amalgamatedPath("c"), "-lpcre2-8", "-ldl", "-Wl,-export-dynamic"],
arguments: ["cc", ...flags, "-o", amalgamatedPath("exe"), amalgamatedPath("c"), "-lpcre2-8", "-ldl", "-lz", "-lcrypt"],
file: amalgamatedPath("c"),
},
ii: {
Expand Down
7 changes: 3 additions & 4 deletions amalgamate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ set -euox pipefail

rust_dir=lighttpd_rust_amalgamated

cmake -Wno-dev
make clean
bear -- make lighttpd
make mod_{indexfile,dirlisting,staticfile}
LIGHTTPD_STATIC=yes ./configure -C --enable-static=yes
make -C src parsers versionstamp
bear -- make -C src lighttpd
Comment on lines +8 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
make -C src parsers versionstamp
bear -- make -C src lighttpd
make -C ./src parsers versionstamp
bear -- make -C ./src lighttpd

Reads a bit clearer I think since it differentiates the arguments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a make clean like before or no?

./amalgamate.mjs | "${SHELL}" -euox pipefail
c2rust transpile --overwrite-existing --emit-build-files --binary lighttpd_amalgamated --output-dir ${rust_dir} amalgamated.compile_commands.json
cp {rust,${rust_dir}}/build.rs
Expand Down
24 changes: 12 additions & 12 deletions lighttpd_rust_amalgamated/Cargo.lock

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

6 changes: 2 additions & 4 deletions lighttpd_rust_amalgamated/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name = "lighttpd_rust_amalgamated"
version = "0.1.0"
edition = "2021"

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

[dependencies]
c2rust-bitfields = "0.17.0"
libc = "0.2.140"
c2rust-bitfields = "0.18.0"
libc = "0.2.154"
1 change: 1 addition & 0 deletions lighttpd_rust_amalgamated/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fn main() {
// add unix dependencies below
// println!("cargo:rustc-flags=-l readline");
println!("cargo:rustc-link-lib=pcre2-8");
println!("cargo:rustc-link-lib=z");
println!("cargo:rustc-link-lib=crypt");
println!("cargo:rustc-link-arg=-Wl,-export-dynamic");
}
Expand Down
Loading