Skip to content

Commit 3cfbf23

Browse files
committed
Source build now relies on pkg-config
1 parent ce6b170 commit 3cfbf23

File tree

10 files changed

+62
-46
lines changed

10 files changed

+62
-46
lines changed

sources/default.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{ stdenv, boost, openssl, lowdown, nlohmann_json, brotli, libsodium, editline
2-
, gnutar, coreutils, findutils, python3, nix
2+
, gnutar, coreutils, findutils, python3, nix, libarchive
33
, automake, autoconf-archive, autoconf, m4, bc, libtool, pkg-config
44
# External source for Nix
55
, nix-source ? nix.src
@@ -56,6 +56,10 @@ let
5656
'';
5757
dest = "libbrotlicommon";
5858
};
59+
libarchive_configured_src = mkConfiguredSrc
60+
{ pkg = libarchive;
61+
confScript = "./build/autogen.sh";
62+
};
5963

6064
srcs_simple =
6165
[ openssl
@@ -69,6 +73,7 @@ let
6973
[ nix_configured_src
7074
editline_configured_src
7175
brotli_configured_src
76+
libarchive_configured_src
7277
];
7378
in stdenv.mkDerivation {
7479
name = "nixie-sources";

src/builders.ab

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,19 @@ pub fun try_build_nix()
5858
if get_osname() == "Darwin":
5959
darwin_export_sdk()
6060

61-
trust env_var_set("step_total", "8")
61+
trust env_var_set("step_total", "9")
6262

6363
dir_create(get_source_root())
64-
dir_create("{cache_root}/nix-lib")
64+
dir_create("{cache_root}/nix-deps/lib/pkgconfig")
6565

6666
build_openssl()?
6767
build_boost()?
6868
build_nlohmann_json()?
6969
build_lowdown()?
70-
// pkgconf name env var lib prefix include prefix
71-
build_autoconf_dep("libbrotlicommon", "LIBBROTLI", "", "c/include")?
72-
build_autoconf_dep("libsodium", "SODIUM", "src/libsodium", "src/libsodium/include")?
73-
build_autoconf_dep("libeditline", "EDITLINE", "src", "include")?
70+
// pkgconf name include prefix
71+
build_autoconf_dep("libbrotlicommon", "c/include")?
72+
build_autoconf_dep("libsodium", "src/libsodium/include")?
73+
build_autoconf_dep("libeditline", "include")?
74+
build_autoconf_dep("libarchive", "libarchive")?
7475
build_nix()?
7576
}

src/builders/autoconf.ab

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ import { pkg_exists, step_title, get_source_root } from "./common.ab"
1313
///
1414
/// ### Arguments:
1515
/// - `lib_name`: The library to check for with `pkg-config`
16-
/// - `var_name`: The variable to export library locations
17-
/// - `lib_prefix`: Where in the source tree the resulting libraries are found
1816
/// - `inc_prefix`: Where in the source tree the build headers are found
19-
pub fun build_autoconf_dep(lib_name: Text, var_name: Text,
20-
lib_prefix: Text = "",
21-
inc_prefix: Text = ""): Null?
17+
pub fun build_autoconf_dep(lib_name: Text, inc_prefix: Text = ""): Null?
2218
{
2319
let source_root = get_source_root()
2420
let cache_root = get_cache_root()
@@ -32,14 +28,10 @@ pub fun build_autoconf_dep(lib_name: Text, var_name: Text,
3228

3329
pull_source_file(lib_name, my_source)?
3430

35-
$(unset C_INCLUDE_PATH CPLUS_INCLUDE_PATH && cd {my_source} && ./configure && make)$?
36-
37-
$cp {my_source}/{lib_prefix}/.libs/* {cache_root}/nix-lib/$?
38-
trust $rm {cache_root}/nix-lib/*.o$
39-
40-
trust env_var_set("{var_name}_LIBS", "{cache_root}/nix-lib")
41-
trust env_var_set("{var_name}_CFLAGS", "-I{my_source}/{inc_prefix}/include")
42-
trust $export {var_name}_LIBS {var_name}_CFLAGS$
31+
$( unset C_INCLUDE_PATH CPLUS_INCLUDE_PATH \
32+
&& cd {my_source} \
33+
&& ./configure --prefix={cache_root}/nix-deps \
34+
&& make && make install )$?
4335

4436
trust $export C_INCLUDE_PATH={my_source}/{inc_prefix}:\$C_INCLUDE_PATH$
4537
trust $export CPLUS_INCLUDE_PATH={my_source}/{inc_prefix}:\$CPLUS_INCLUDE_PATH$
@@ -48,18 +40,16 @@ pub fun build_autoconf_dep(lib_name: Text, var_name: Text,
4840
main(cmdl)
4941
{
5042
if len(cmdl) < 5 {
51-
echo "Usage: ./autoconf.sh <package> <var_name> <lib_prefix> <inc_prefix>"
43+
echo "Usage: ./autoconf.sh <package> <inc_prefix>"
5244
echo ""
5345
echo "See builders/autoconf.ab and builders.ab for more info"
5446
exit 1
5547
}
5648

5749
let lib_name = cmdl[1]
58-
let var_name = cmdl[2]
59-
let lib_prefix = cmdl[3]
60-
let inc_prefix = cmdl[4]
50+
let inc_prefix = cmdl[2]
6151

6252
trust env_var_set("_NIXIE_TESTING_SKIP_TARBALL", "1")
6353
trust env_var_set("step_total", "1")
64-
build_autoconf_dep(lib_name, var_name, lib_prefix, inc_prefix)?
54+
build_autoconf_dep(lib_name, inc_prefix)?
6555
}

src/builders/lowdown.ab

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ fun macos_build_post()
1818
/// This function runs within the source directory, in a subshell.
1919
fun build_lowdown_inner()
2020
{
21-
$./configure$?
21+
let cache_root = get_cache_root()
22+
23+
$./configure PREFIX={cache_root}/nix-deps$?
2224
$make$?
2325

2426
if get_osname() == "Darwin":
2527
macos_build_post()?
28+
$make install_shared$?
2629
}
2730

2831
/// This is the core function for the Lowdown builder.
@@ -42,9 +45,6 @@ pub fun build_lowdown()
4245

4346
$(cd {source_root}/lowdown && {nameof build_lowdown_inner})$?
4447

45-
trust env_var_set("LOWDOWN_LIBS", "{cache_root}/nix-lib")
46-
trust env_var_set("LOWDOWN_CFLAGS", "-I{source_root}/lowdown")
47-
4848
trust $export C_INCLUDE_PATH={source_root}/lowdown:\$C_INCLUDE_PATH$
4949
trust $export CPLUS_INCLUDE_PATH={source_root}/lowdown:\$CPLUS_INCLUDE_PATH$
5050
}

src/builders/nix.ab

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under GNU GPLv2
33
// Builder for the Nix package manager itself
44

5+
import { env_var_set } from "std/env"
56
import { file_exists, dir_exists, dir_create } from "std/fs"
67

78
import { pull_source_file } from "../resources.ab"
@@ -46,7 +47,8 @@ pub fun build_nix()
4647

4748
$python3 -m venv --system-site-packages "{venv}"$?
4849

49-
trust $export LIBRARY_PATH={cache_root}/nix-lib:\$LIBRARY_PATH$
50+
trust $export LIBRARY_PATH={cache_root}/nix-deps/lib:\$LIBRARY_PATH$
51+
trust $export PKG_CONFIG_PATH={cache_root}/nix-deps/lib/pkgconfig:{cache_root}/nix-deps/share/pkgconfig:\$PKG_CONFIG_PATH$
5052

5153
${venv}/bin/pip install meson ninja$?
5254

@@ -57,10 +59,7 @@ pub fun build_nix()
5759

5860
main(cmdl)
5961
{
60-
echo "This builder only makes sense in the wrapper context,"
61-
echo "where all dependencies were built and/or resolved."
62-
echo ""
63-
echo "Use ./nix --nixie-no-precompiled to test the full build chain."
64-
65-
exit 1
62+
trust env_var_set("_nixie_testing_skip_tarball", "1")
63+
trust env_var_set("step_total", "1")
64+
build_nix()?
6665
}

src/builders/nlohmann_json.ab

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
// Builder for NLohmann's JSON library
44

55
import { env_var_set } from "std/env"
6+
import { file_write } from "std/fs"
67

78
import { pull_source_file } from "../resources.ab"
9+
import { get_cache_root } from "../platform.ab"
810

911
import { pkg_exists, step_title, get_source_root } from "./common.ab"
1012

@@ -14,6 +16,7 @@ import { pkg_exists, step_title, get_source_root } from "./common.ab"
1416
pub fun build_nlohmann_json()
1517
{
1618
let source_root = get_source_root()
19+
let cache_root = get_cache_root()
1720

1821
step_title("nlohmann_json")
1922

@@ -22,6 +25,14 @@ pub fun build_nlohmann_json()
2225

2326
pull_source_file("nlohmann_json", "{source_root}/nlohmann_json")?
2427

28+
let version = trust $grep "^version:" {source_root}/nlohmann_json/wsjcpp.yml | cut -d '"' -f 2 | cut -d 'v' -f 2$
29+
30+
file_write("{cache_root}/nix-deps/lib/pkgconfig/nlohmann_json.pc",
31+
"Name: nlohmann_json
32+
Version: {version}
33+
Description: JSON for Modern C++
34+
Cflags: -I{source_root}/nlohmann_json/include")?
35+
2536
trust env_var_set("NLOHMANN_JSON_LIBS", "{source_root}/nlohmann_json/single_include")
2637
trust env_var_set("NLOHMANN_JSON_CFLAGS", "{source_root}/nlohmann_json/single_include")
2738
trust $export NLOHMANN_JSON_LIBS NLOHMANN_JSON_CFLAGS$

src/builders/openssl.ab

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ fun build_openssl_inner()
2929

3030
trust $chmod +x ./config$
3131

32-
$./config$?
32+
$./config --prefix={cache_root}/nix-deps$?
3333
make_headers()?
34-
$make libcrypto.{dll_ext}$?
35-
36-
trust $cp ./libcrypto.* {cache_root}/nix-lib/$
34+
$make libcrypto.{dll_ext} libcrypto.pc$?
35+
36+
// Building libssl is:
37+
// - hard
38+
// - broken
39+
// - a very bad idea anyway
40+
// so we're performing the install ourselves
41+
trust $cp ./libcrypto.* {cache_root}/nix-deps/lib/$
42+
trust $cp ./libcrypto.pc {cache_root}/nix-deps/lib/pkgconfig$
43+
trust $cp -r ./include {cache_root}/nix-deps/$
3744
}
3845

3946
/// This is the core function for the OpenSSL builder.
@@ -56,7 +63,7 @@ pub fun build_openssl()
5663
// Using a subshell ensures we aren't cd elsewhere on failure
5764
$(cd {source_root}/openssl && {nameof build_openssl_inner})$?
5865

59-
trust env_var_set("OPENSSL_LIBS", "{cache_root}/nix-lib")
66+
trust env_var_set("OPENSSL_LIBS", "{cache_root}/nix-deps/lib")
6067
trust env_var_set("OPENSSL_CFLAGS", "-I{source_root}/openssl/include")
6168
trust $export OPENSSL_LIBS OPENSSL_CFLAGS$
6269

src/cli.ab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fun cmd_cleanup()
5656
trust $rm -rf {nix_root}$
5757

5858
echo "Removing retrieved Nix binaries..."
59-
trust $rm -rf {cache_root}/nix-static {cache_root}/nix-lib$
59+
trust $rm -rf {cache_root}/nix-static {cache_root}/nix-lib {cache_root}/nix-deps$
6060

6161
exit 0
6262
}

src/nix.ab

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fun get_nix()
4646
let system = get_system()
4747

4848
let nix_path = "{cache_root}/nix-static"
49-
let fakedir_path = "{cache_root}/nix-lib/libfakedir.dylib"
49+
let fakedir_path = "{cache_root}/nix-deps/lib/libfakedir.dylib"
5050

5151
enter_alt_buffer()
5252
set_title("Building Nix...")
@@ -56,7 +56,7 @@ fun get_nix()
5656

5757
// Unpack fakedir as needed
5858
if osname == "Darwin" and not file_exists(fakedir_path) {
59-
dir_create("{cache_root}/nix-lib")
59+
dir_create("{cache_root}/nix-deps/lib")
6060
pull_binary("libfakedir.dylib", fakedir_path) failed {
6161
teardown(true)
6262
fail 1
@@ -176,7 +176,7 @@ fun launch_darwin_workaround(name: Text, nix_path: Text, args: [Text]): Null
176176
let cache_root = get_cache_root()
177177
let nix_root = get_nix_root()
178178

179-
let fakedir_path = "{cache_root}/nix-lib/libfakedir.dylib"
179+
let fakedir_path = "{cache_root}/nix-deps/lib/libfakedir.dylib"
180180

181181
trust env_var_set("FAKEDIR_PATTERN", "/nix")
182182
trust env_var_set("FAKEDIR_TARGET", "{nix_root}/nix")
@@ -187,7 +187,7 @@ fun launch_darwin_workaround(name: Text, nix_path: Text, args: [Text]): Null
187187
// Unfortunately, this requires us to disable the Nix sandbox entirely.
188188
trust $ _NIX_TEST_NO_SANDBOX=1 \
189189
DYLD_INSERT_LIBRARIES="{fakedir_path}" \
190-
DYLD_LIBRARY_PATH="{cache_root}/nix-lib" \
190+
DYLD_LIBRARY_PATH="{cache_root}/nix-deps/lib" \
191191
exec -a {name} {nix_path} "{args}"$
192192
}
193193

src/resources.ab

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ pub fun pull_source_file(member: Text, dest: Text): Null?
6464
where = "{tmpd}/{member}"
6565
}
6666

67+
// Our build method means source dirs accumulate state, we're better off
68+
// throwing them away.
69+
trust $rm -rf {dest}$
6770
trust mv where dest
6871
}
6972

0 commit comments

Comments
 (0)