diff --git a/.circleci/config.yml b/.circleci/config.yml index a5d250f2fb..7df5832ee2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -116,14 +116,17 @@ jobs: ninja -C build-clang test - run: - name: Install shared library + name: Test building with meson subproject command: | - meson build-install c --prefix=/usr - sudo ninja -C build-install install + meson build-subproject c/tests/meson-subproject + ninja -C build-subproject + ./build-subproject/example - run: - name: Hand-compile some example programs + name: Install shared library and hand-compile program. command: | + meson build-install c --prefix=/usr + sudo ninja -C build-install install clang c/examples/api_structure.c -o api_structure -ltskit ./api_structure diff --git a/.gitmodules b/.gitmodules index d5a2923ff5..08c84692c3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "c/kastore"] - path = c/kastore + path = c/subprojects/full-projects/kastore url = https://github.com/tskit-dev/kastore.git diff --git a/c/kastore b/c/kastore deleted file mode 160000 index fb5933b64b..0000000000 --- a/c/kastore +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fb5933b64b669b8126c4ac614788661dd0c248d2 diff --git a/c/meson.build b/c/meson.build index 90276bef6b..ebef478e08 100644 --- a/c/meson.build +++ b/c/meson.build @@ -1,11 +1,11 @@ project('tskit', ['c', 'cpp'], default_options: ['c_std=c99', 'cpp_std=c++11']) -kastore_dir=join_paths(meson.source_root(), 'kastore/c') -add_global_arguments(['-I' + kastore_dir], language: ['c', 'cpp']) +kastore_proj = subproject('kastore') +kastore_dep = kastore_proj.get_variable('kastore_dep') cc = meson.get_compiler('c') m_dep = cc.find_library('m', required: false) -lib_deps = [m_dep] +lib_deps = [m_dep, kastore_dep] extra_c_args = [ '-Wall', '-Wextra', '-Werror', '-Wpedantic', '-W', @@ -15,85 +15,85 @@ extra_c_args = [ '-fshort-enums', '-fno-common'] lib_sources = [ - 'kastore/c/kastore.c', 'tskit/core.c', 'tskit/tables.c', 'tskit/trees.c', + 'tskit/core.c', 'tskit/tables.c', 'tskit/trees.c', 'tskit/genotypes.c', 'tskit/stats.c', 'tskit/convert.c'] lib_headers = [ 'tskit/core.h', 'tskit/tables.h', 'tskit/trees.h', 'tskit/genotypes.h', 'tskit/stats.h', 'tskit/convert.h'] +# Subprojects use the static library for simplicity. +inc = include_directories(['.', 'tskit']) +tskit_lib = static_library('tskit', + sources: lib_sources, dependencies: lib_deps) +tskit_dep = declare_dependency(include_directories:inc, link_with: tskit_lib) -# Shared library install target. -shared_library('tskit', - sources: lib_sources, dependencies: lib_deps, c_args: extra_c_args, install: true) -# FIXME for now we include the kastore header because the shared lib won't -# work otherwise. Will need to come up with a better solution for this. -install_headers('kastore/c/kastore.h') -install_headers('tskit.h') -install_headers(lib_headers, subdir: 'tskit') +if not meson.is_subproject() -# Static library for building tests and examples. -tskit_lib = static_library('tskit', - sources: lib_sources, dependencies: lib_deps, c_args: extra_c_args) + # Shared library install target. + shared_library('tskit', + sources: lib_sources, dependencies: lib_deps, c_args: extra_c_args, install: true) + install_headers('tskit.h') + install_headers(lib_headers, subdir: 'tskit') -cunit_dep = dependency('cunit', required: false) -if cunit_dep.found() + cunit_dep = dependency('cunit') # We don't specify extra C args here as CUnit won't pass the checks. test_lib = static_library('testlib', - sources: ['tests/testlib.c'], dependencies: cunit_dep) + sources: ['tests/testlib.c'], dependencies: [cunit_dep, kastore_dep]) test_core = executable('test_core', sources: ['tests/test_core.c'], - link_with: [tskit_lib, test_lib], c_args: extra_c_args) + link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep) test('core', test_core) test_tables = executable('test_tables', sources: ['tests/test_tables.c'], - link_with: [tskit_lib, test_lib], c_args: extra_c_args) + link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep) test('tables', test_tables) test_trees = executable('test_trees', sources: ['tests/test_trees.c'], - link_with: [tskit_lib, test_lib], c_args: extra_c_args) + link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep) test('trees', test_trees) test_genotypes = executable('test_genotypes', sources: ['tests/test_genotypes.c'], - link_with: [tskit_lib, test_lib], c_args: extra_c_args) + link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep) test('genotypes', test_genotypes) test_convert = executable('test_convert', sources: ['tests/test_convert.c'], - link_with: [tskit_lib, test_lib], c_args: extra_c_args) + link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep) test('convert', test_convert) test_stats = executable('test_stats', sources: ['tests/test_stats.c'], - link_with: [tskit_lib, test_lib], c_args: extra_c_args) + link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep) test('stats', test_stats) -endif -test_minimal_cpp = executable('test_minimal_cpp', - sources: ['tests/test_minimal_cpp.cpp'], link_with: [tskit_lib]) -test('minimal_cpp', test_minimal_cpp) - -# The development CLI. Don't use extra C args because argtable code won't pass -executable('dev-cli', - sources: ['dev-tools/dev-cli.c', 'dev-tools/argtable3.c'], - link_with: [tskit_lib], c_args:['-Dlint']) - -# Example programs. -executable('api_structure', - sources: ['examples/api_structure.c'], link_with: [tskit_lib]) -executable('error_handling', - sources: ['examples/error_handling.c'], link_with: [tskit_lib]) -executable('tree_iteration', - sources: ['examples/tree_iteration.c'], link_with: [tskit_lib]) - -gsl_dep = dependency('gsl', required: false) -if gsl_dep.found() - executable('haploid_wright_fisher', - sources: ['examples/haploid_wright_fisher.c'], link_with: [tskit_lib], - dependencies: [gsl_dep]) + test_minimal_cpp = executable('test_minimal_cpp', + sources: ['tests/test_minimal_cpp.cpp'], link_with: [tskit_lib], + dependencies: kastore_dep) + test('minimal_cpp', test_minimal_cpp) + + # The development CLI. Don't use extra C args because argtable code won't pass + executable('dev-cli', + sources: ['dev-tools/dev-cli.c', 'dev-tools/argtable3.c'], + link_with: [tskit_lib], c_args:['-Dlint'], dependencies: kastore_dep) + + # Example programs. + executable('api_structure', + sources: ['examples/api_structure.c'], link_with: [tskit_lib], dependencies: lib_deps) + executable('error_handling', + sources: ['examples/error_handling.c'], link_with: [tskit_lib], dependencies: lib_deps) + executable('tree_iteration', + sources: ['examples/tree_iteration.c'], link_with: [tskit_lib], dependencies: lib_deps) + + gsl_dep = dependency('gsl', required: false) + if gsl_dep.found() + executable('haploid_wright_fisher', + sources: ['examples/haploid_wright_fisher.c'], link_with: [tskit_lib], + dependencies: [gsl_dep, lib_deps]) + endif endif # TMP: until we've ported all the tests, keep this compilable. diff --git a/c/subprojects/full-projects/kastore b/c/subprojects/full-projects/kastore new file mode 160000 index 0000000000..b15f21c0c0 --- /dev/null +++ b/c/subprojects/full-projects/kastore @@ -0,0 +1 @@ +Subproject commit b15f21c0c0d0a12800836154af4180e94a0714b5 diff --git a/c/subprojects/kastore b/c/subprojects/kastore new file mode 120000 index 0000000000..ee3ac9b241 --- /dev/null +++ b/c/subprojects/kastore @@ -0,0 +1 @@ +full-projects/kastore/c/ \ No newline at end of file diff --git a/c/tests/meson-subproject/example.c b/c/tests/meson-subproject/example.c new file mode 100644 index 0000000000..05b2d81c73 --- /dev/null +++ b/c/tests/meson-subproject/example.c @@ -0,0 +1,59 @@ +/* Simple example testing that we compile and link in tskit and kastore + * when we use meson submodules. + */ +#include +#include +#include +#include + +void +test_kas_strerror() +{ + printf("test_kas_strerror\n"); + const char *str = kas_strerror(KAS_ERR_NO_MEMORY); + assert(strcmp(str, "Out of memory") == 0); +} + +void +test_strerror() +{ + printf("test_strerror\n"); + const char *str = tsk_strerror(TSK_ERR_NO_MEMORY); + assert(strcmp(str, "Out of memory") == 0); +} + +void +test_load_error() +{ + printf("test_open_error\n"); + tsk_treeseq_t ts; + int ret = tsk_treeseq_load(&ts, "no such file", 0); + assert(tsk_is_kas_error(ret)); + tsk_treeseq_free(&ts); +} + +void +test_table_basics() +{ + printf("test_table_basics\n"); + tsk_table_collection_t tables; + int ret = tsk_table_collection_init(&tables, 0); + assert(ret == 0); + + ret = tsk_node_table_add_row(&tables.nodes, 0, 1.0, TSK_NULL, TSK_NULL, NULL, 0); + assert(ret == 0); + ret = tsk_node_table_add_row(&tables.nodes, 0, 2.0, TSK_NULL, TSK_NULL, NULL, 0); + assert(ret == 1); + assert(tables.nodes.num_rows == 2); + + tsk_table_collection_free(&tables); +} + +int main() +{ + test_kas_strerror(); + test_strerror(); + test_load_error(); + test_table_basics(); + return 0; +} diff --git a/c/tests/meson-subproject/meson.build b/c/tests/meson-subproject/meson.build new file mode 100644 index 0000000000..ee4218db18 --- /dev/null +++ b/c/tests/meson-subproject/meson.build @@ -0,0 +1,12 @@ +project('example', 'c') + +kastore_proj = subproject('kastore') +kastore_dep = kastore_proj.get_variable('kastore_dep') +tskit_proj = subproject('tskit') +tskit_dep = tskit_proj.get_variable('tskit_dep') + +executable('example', + 'example.c', + dependencies : [kastore_dep, tskit_dep], + install : true) + diff --git a/c/tests/meson-subproject/subprojects/kastore b/c/tests/meson-subproject/subprojects/kastore new file mode 120000 index 0000000000..ff09d40cad --- /dev/null +++ b/c/tests/meson-subproject/subprojects/kastore @@ -0,0 +1 @@ +../../../subprojects/full-projects/kastore/c/ \ No newline at end of file diff --git a/c/tests/meson-subproject/subprojects/tskit b/c/tests/meson-subproject/subprojects/tskit new file mode 120000 index 0000000000..1b20c9fb81 --- /dev/null +++ b/c/tests/meson-subproject/subprojects/tskit @@ -0,0 +1 @@ +../../../ \ No newline at end of file diff --git a/python/MANIFEST.in b/python/MANIFEST.in index b918a4ab8d..efefe9f1fe 100644 --- a/python/MANIFEST.in +++ b/python/MANIFEST.in @@ -1,4 +1,4 @@ -include lib/kastore/c/kastore.h +include lib/subprojects/kastore/kastore.h include lib/tskit.h include lib/tskit/*.h include LICENSE diff --git a/python/setup.py b/python/setup.py index 59878144c6..9db138ff71 100644 --- a/python/setup.py +++ b/python/setup.py @@ -25,7 +25,7 @@ def finalize_options(self): libdir = "lib" -kastore_dir = os.path.join(libdir, "kastore", "c") +kastore_dir = os.path.join(libdir, "subprojects", "kastore") tsk_source_files = [ "core.c", "tables.c",