Skip to content
Draft
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
9 changes: 9 additions & 0 deletions ext/h2o/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
});

const wslay = b.dependency("wslay", .{
.target = target,
.optimize = optimize,
});

const h2o_c = b.dependency("h2o", .{
.target = target,
.optimize = optimize,
Expand Down Expand Up @@ -345,6 +350,7 @@ pub fn build(b: *std.Build) !void {
h2o.linkLibrary(libyrmcds);
h2o.linkLibrary(picohttpparser);
h2o.linkLibrary(picotls);
h2o.linkLibrary(wslay.artifact("wslay"));
// h2o.linkLibrary(ssl_conservatory);
h2o.linkLibC();

Expand All @@ -354,6 +360,7 @@ pub fn build(b: *std.Build) !void {
h2o.addIncludePath(h2o_c.path("include"));
h2o.addIncludePath(h2o_c.path("include/h2o"));
h2o.addIncludePath(h2o_c.path("include/h2o/socket"));
h2o.addIncludePath(wslay.path("lib/includes"));

h2o.addCSourceFiles(.{
.root = h2o_c.path("lib"),
Expand Down Expand Up @@ -425,6 +432,7 @@ pub fn build(b: *std.Build) !void {
"http2/http2_debug_state.c",
"http2/scheduler.c",
"http2/stream.c",
"websocket.c",
"tunnel.c",
},
.flags = &.{
Expand All @@ -435,6 +443,7 @@ pub fn build(b: *std.Build) !void {
"-pthread",
"-DH2O_USE_LIBUV",
"-DH2O_USE_PICOTLS",
"-DWSLAY_VERSION=\\\"1.1.1\\\"",
if (t.os.tag == .linux) "-D_GNU_SOURCE" else "",
},
});
Expand Down
3 changes: 3 additions & 0 deletions ext/h2o/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
.url = "https://github.com/DLTcollab/sse2neon/archive/refs/tags/v1.5.1.tar.gz",
.hash = "N-V-__8AAPihCgDO1A74r0pFZaoafeZ41DR435smSDwGLbLb",
},
.wslay = .{
.path = "../wslay",
},
.patches = .{
.path = "./patches",
},
Expand Down
60 changes: 60 additions & 0 deletions ext/wslay/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const std = @import("std");

const wslay_version = "1.1.1";

pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const t = target.result;

const wslay_src = b.dependency("wslay", .{
.target = target,
.optimize = optimize,
});

const lib = b.addStaticLibrary(.{
.name = "wslay",
.target = target,
.optimize = optimize,
});

lib.linkLibC();

lib.addIncludePath(wslay_src.path("lib"));
lib.addIncludePath(wslay_src.path("lib/includes"));

var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();

try flags.append("-fno-sanitize=all");
try flags.append(b.fmt("-DWSLAY_VERSION=\\\"{s}\\\"", .{wslay_version}));

if (t.os.tag == .windows) {
try flags.append("-DHAVE_WINSOCK2_H=1");
} else {
try flags.append("-DHAVE_ARPA_INET_H=1");
try flags.append("-DHAVE_NETINET_IN_H=1");
}

if (t.cpu.arch.endian() == .big) {
try flags.append("-DWORDS_BIGENDIAN=1");
}

lib.addCSourceFiles(.{
.root = wslay_src.path("lib"),
.files = &.{
"wslay_event.c",
"wslay_frame.c",
"wslay_net.c",
"wslay_queue.c",
"wslay_stack.c",
},
.flags = flags.items,
});

lib.installHeadersDirectory(wslay_src.path("lib/includes"), "", .{
.include_extensions = &.{".h"},
});

b.installArtifact(lib);
}
13 changes: 13 additions & 0 deletions ext/wslay/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.{
.name = "wslay",
.version = "0.0.1",
.dependencies = .{
.wslay = .{
.url = "https://github.com/tatsuhiro-t/wslay/archive/refs/tags/release-1.1.1.tar.gz",
.hash = "N-V-__8AADdLBADNETOk9pvYZ-k7F8a08-U43YCrYSlxu621",
},
},
.paths = .{
"",
},
}
55 changes: 34 additions & 21 deletions flake.lock

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

141 changes: 22 additions & 119 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,127 +1,30 @@
{
description = "Vere build devshell";
description = "default devshell";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};

outputs = inputs@{ self, nixpkgs, parts }: parts.lib.mkFlake { inherit inputs; } (let
# map systems to the musl-cross-make target names; only
# x86_64-linux is tested though
toolchainTargets = {
"x86_64-linux" = "x86_64-linux-musl";
"aarch64-linux" = "aarch64-linux-musl";
};
# map dep urls to hashes
toolchainDeps = {
"https://ftpmirror.gnu.org/gnu/gcc/gcc-9.4.0/gcc-9.4.0.tar.xz" = "13l3p6g2krilaawbapmn9zmmrh3zdwc36mfr3msxfy038hps6pf9";
"https://ftpmirror.gnu.org/gnu/binutils/binutils-2.33.1.tar.xz" = "1grcf8jaw3i0bk6f9xfzxw3qfgmn6fgkr108isdkbh1y3hnzqrmb";
"https://musl.libc.org/releases/musl-1.2.3.tar.gz" = "196lrzw0qy5axiz9p5ay50q2mls8hbfckr4rw0klc7jjc9h0nnvx";
"https://ftpmirror.gnu.org/gnu/gmp/gmp-6.1.2.tar.bz2" = "1clg7pbpk6qwxj5b2mw0pghzawp2qlm3jf9gdd8i6fl6yh2bnxaj";
"https://ftpmirror.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz" = "0biwnhjm3rx3hc0rfpvyniky4lpzsvdcwhmcn7f0h4iw2hwcb1b9";
"https://ftpmirror.gnu.org/gnu/mpfr/mpfr-4.0.2.tar.bz2" = "1k1s4p56272bggvyrxfn3zdycr4wy7h5ipac70cr03lys013ypn0";
"http://ftp.barfooze.de/pub/sabotage/tarballs//linux-headers-4.19.88-1.tar.xz" = "04r8k4ckqbklx9sfm07cr7vfw5ra4cic0rzanm9dfh0crxncfnwr";
"http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=3d5db9ebe860" = "75d5d255a2a273b6e651f82eecfabf6cbcd8eaeae70e86b417384c8f4a58d8d3";
};
in {
systems = builtins.attrNames toolchainTargets;

flake = {};

perSystem = { pkgs, system, ... }: let
target = toolchainTargets.${system};

# in order to make the toolchain derivation pure, spoof `wget`
# to use FODs for the dependencies that would otherwise be
# downloaded
pseudoWget = let
c = pkgs.coreutils;
in pkgs.writeScriptBin "wget" ''
#!${pkgs.stdenv.shell}

declare -A targets
${builtins.concatStringsSep "\n"
(builtins.map (url:
"targets[${nixpkgs.lib.escapeShellArg url}]=" + (nixpkgs.lib.escapeShellArg (pkgs.fetchurl {
inherit url;
sha256 = builtins.getAttr url toolchainDeps;
})))
(builtins.attrNames toolchainDeps))}

# -c -O target url
target="$3"
url="$4"
preFetched=${"$" + "{targets[$url]}"}
if [[ -z "$preFetched" ]]; then
${c}/bin/echo 1>&2 "$target ($url) is new or changed, nix-prefetch-url it and add or update the url and hash in toolchainDeps in flake.nix"
exit 1
fi
${c}/bin/cp --reflink=auto "$preFetched" "$target"
'';

toolchain = let
# keep in sync with `_musl_cross_make_version` in
# bazel/toolchain/BUILD.bazel
version = "fe915821b652a7fa37b34a596f47d8e20bc72338";

# `-g -O2` are the defaults (there's no way to add cflags via
# config.mak), `-Wno-format-security` is the interesting
# addition (without which gcc build fails in several places
# due to `-Werror=format-security` being on for some reason)
commonCFLAGS = "-g -O2 -Wno-format-security";
in pkgs.stdenv.mkDerivation {
name = "musl-cross-make";
inherit system version;
src = pkgs.fetchFromGitHub {
owner = "richfelker";
repo = "musl-cross-make";
rev = version;
sha256 = "sha256-FthfhZ+qGf2nWLICvjaO8fiP5+PYU7PqFCbPwXmJFes=";
outputs = {
self,
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem
(
system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
clang-tools
zig_0_14
zls
llvm_19
];
};

nativeBuildInputs = [
pseudoWget
];

enableParallelBuilding = true;
configurePhase = ''
cat > config.mak <<EOF
TARGET = ${target}
OUTPUT = $out
COMMON_CONFIG += CFLAGS="${commonCFLAGS}" CXXFLAGS="${commonCFLAGS}"
EOF
'';
};
in {
devShells.default = (pkgs.buildFHSUserEnvBubblewrap {
name = "vere-devenv";
targetPkgs = pkgs: [
toolchain
]
++ (with pkgs; [
autoconf
autoconf-archive
automake
bazel_6
binutils # for `nm`
jdk11_headless
libtool
m4
pkg-config
git
perl
]);
extraBuildCommands = ''
chmod +w usr
mkdir -p usr/local
# symlinking breaks Bazel inclusion checks, so have to copy
cp -a --reflink=auto ${toolchain} usr/local/${target}
'';
}).env;
};
});
}
);
}
Loading