Skip to content

Commit 15db1e2

Browse files
committed
Source build now relies on pkg-config
1 parent ce6b170 commit 15db1e2

File tree

10 files changed

+62
-66
lines changed

10 files changed

+62
-66
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: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { build_autoconf_dep } from "./builders/autoconf.ab"
2020
import { build_nix } from "./builders/nix.ab"
2121

2222
/// Export libraries found inside the macOS SDK for building Nix
23+
///
24+
/// TODO: is this still required with Meson?
2325
fun darwin_export_sdk()
2426
{
2527
// Calling xcrun should prompt the user to install the macOS SDK.
@@ -46,8 +48,8 @@ fun darwin_export_sdk()
4648
/// Build Nix and its dependencies locally, then place it in the expected location
4749
/// in the user's cache directory.
4850
///
49-
/// This process **requires**, among other things, `pkg-config` to determine
50-
/// which dependencies are already met and avoid building them.
51+
/// This process **requires**, among other things, `pkg-config` due to it being
52+
/// the only detection method for many dependencies in Meson.
5153
pub fun try_build_nix()
5254
{
5355
let cache_root = get_cache_root()
@@ -58,18 +60,19 @@ pub fun try_build_nix()
5860
if get_osname() == "Darwin":
5961
darwin_export_sdk()
6062

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

6365
dir_create(get_source_root())
64-
dir_create("{cache_root}/nix-lib")
66+
dir_create("{cache_root}/nix-deps/lib/pkgconfig")
6567

6668
build_openssl()?
6769
build_boost()?
6870
build_nlohmann_json()?
6971
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")?
72+
// pkgconf name include prefix
73+
build_autoconf_dep("libbrotlicommon", "c/include")?
74+
build_autoconf_dep("libsodium", "src/libsodium/include")?
75+
build_autoconf_dep("libeditline", "include")?
76+
build_autoconf_dep("libarchive", "libarchive")?
7477
build_nix()?
7578
}

src/builders/autoconf.ab

Lines changed: 8 additions & 21 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,34 +28,25 @@ 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$
43-
44-
trust $export C_INCLUDE_PATH={my_source}/{inc_prefix}:\$C_INCLUDE_PATH$
45-
trust $export CPLUS_INCLUDE_PATH={my_source}/{inc_prefix}:\$CPLUS_INCLUDE_PATH$
31+
$( unset C_INCLUDE_PATH CPLUS_INCLUDE_PATH \
32+
&& cd {my_source} \
33+
&& ./configure --prefix={cache_root}/nix-deps \
34+
&& make && make install )$?
4635
}
4736

4837
main(cmdl)
4938
{
5039
if len(cmdl) < 5 {
51-
echo "Usage: ./autoconf.sh <package> <var_name> <lib_prefix> <inc_prefix>"
40+
echo "Usage: ./autoconf.sh <package> <inc_prefix>"
5241
echo ""
5342
echo "See builders/autoconf.ab and builders.ab for more info"
5443
exit 1
5544
}
5645

5746
let lib_name = cmdl[1]
58-
let var_name = cmdl[2]
59-
let lib_prefix = cmdl[3]
60-
let inc_prefix = cmdl[4]
47+
let inc_prefix = cmdl[2]
6148

6249
trust env_var_set("_NIXIE_TESTING_SKIP_TARBALL", "1")
6350
trust env_var_set("step_total", "1")
64-
build_autoconf_dep(lib_name, var_name, lib_prefix, inc_prefix)?
51+
build_autoconf_dep(lib_name, inc_prefix)?
6552
}

src/builders/lowdown.ab

Lines changed: 4 additions & 7 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.
@@ -41,12 +44,6 @@ pub fun build_lowdown()
4144
pull_source_file("lowdown", "{source_root}/lowdown")?
4245

4346
$(cd {source_root}/lowdown && {nameof build_lowdown_inner})$?
44-
45-
trust env_var_set("LOWDOWN_LIBS", "{cache_root}/nix-lib")
46-
trust env_var_set("LOWDOWN_CFLAGS", "-I{source_root}/lowdown")
47-
48-
trust $export C_INCLUDE_PATH={source_root}/lowdown:\$C_INCLUDE_PATH$
49-
trust $export CPLUS_INCLUDE_PATH={source_root}/lowdown:\$CPLUS_INCLUDE_PATH$
5047
}
5148

5249
main(cmdl)

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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
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

1113
/// This is the core function for the NLohmann JSON library.
12-
///
13-
/// It exports the `LNLOHMANN_JSON_LIBS` and `NLOHMANN_JSON_CFLAGS` variables.
1414
pub fun build_nlohmann_json()
1515
{
1616
let source_root = get_source_root()
17+
let cache_root = get_cache_root()
1718

1819
step_title("nlohmann_json")
1920

@@ -22,12 +23,13 @@ pub fun build_nlohmann_json()
2223

2324
pull_source_file("nlohmann_json", "{source_root}/nlohmann_json")?
2425

25-
trust env_var_set("NLOHMANN_JSON_LIBS", "{source_root}/nlohmann_json/single_include")
26-
trust env_var_set("NLOHMANN_JSON_CFLAGS", "{source_root}/nlohmann_json/single_include")
27-
trust $export NLOHMANN_JSON_LIBS NLOHMANN_JSON_CFLAGS$
26+
let version = trust $grep "^version:" {source_root}/nlohmann_json/wsjcpp.yml | cut -d '"' -f 2 | cut -d 'v' -f 2$
2827

29-
trust $export C_INCLUDE_PATH={source_root}/nlohmann_json/single_include:\$C_INCLUDE_PATH$
30-
trust $export CPLUS_INCLUDE_PATH={source_root}/nlohmann_json/single_include:\$CPLUS_INCLUDE_PATH$
28+
file_write("{cache_root}/nix-deps/lib/pkgconfig/nlohmann_json.pc",
29+
"Name: nlohmann_json
30+
Version: {version}
31+
Description: JSON for Modern C++
32+
Cflags: -I{source_root}/nlohmann_json/include")?
3133
}
3234

3335
main(cmdl)

src/builders/openssl.ab

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ fun build_openssl_inner()
3131

3232
$./config$?
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.
@@ -55,13 +62,6 @@ pub fun build_openssl()
5562

5663
// Using a subshell ensures we aren't cd elsewhere on failure
5764
$(cd {source_root}/openssl && {nameof build_openssl_inner})$?
58-
59-
trust env_var_set("OPENSSL_LIBS", "{cache_root}/nix-lib")
60-
trust env_var_set("OPENSSL_CFLAGS", "-I{source_root}/openssl/include")
61-
trust $export OPENSSL_LIBS OPENSSL_CFLAGS$
62-
63-
trust $export C_INCLUDE_PATH={source_root}/openssl/include:\$C_INCLUDE_PATH$
64-
trust $export CPLUS_INCLUDE_PATH={source_root}/openssl/include:\$CPLUS_INCLUDE_PATH$
6565
}
6666

6767
main(cmdl)

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)