Skip to content

Commit

Permalink
Regenerate Julia interface to ViennaRNA header files
Browse files Browse the repository at this point in the history
- update to Clang.jl v0.18.1

- include header files for constraints, this needs a patch to the
  ViennaRNA header files to be able to be parsed by Clang.jl

- the gen/patches-for-headers directory contains the patches to be
  applied to the ViennaRNA header files, with the patches only applied
  to a temporary copy of the header files that are used to generate
  the Julia interface
  • Loading branch information
marcom committed Apr 14, 2024
1 parent 69deb25 commit be10f86
Show file tree
Hide file tree
Showing 5 changed files with 6,165 additions and 5,538 deletions.
2 changes: 1 addition & 1 deletion gen/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"

[compat]
Clang = "0.17.1"
Clang = "0.18.1"
julia = "1.7"
14 changes: 13 additions & 1 deletion gen/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# How to generate the wrappers
# ViennaRNA libRNA wrapper generator

## How to generate the wrappers

1. `cd` to this directory
2. run `julia --project generator.jl`
Expand All @@ -7,3 +9,13 @@

1. `cd` to this directory
2. run `julia --project` and then in the Julia REPL, run `pkg> up`

## Notes on patches to headers

Some headers of ViennaRNA have to be patched to be able to be parsed
by Clang.jl. These patches can be found are under the directory
`patches-for-headers/`. The patches are applied to a temporary copy
of the header files that is deleted after parsing by the
`generator.jl` script that generates the `../lib/LibRNA.jl` file.
This only needs to be done once on a developer's machine when the
header files change.
36 changes: 34 additions & 2 deletions gen/generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import Pkg
cd(@__DIR__)
Pkg.activate(".")

function find_files_matching_regex(root_dir::AbstractString, regex::Regex)
matching_files = String[]
for (root, dirs, files) in walkdir(root_dir)
for file in files
if occursin(regex, file)
push!(matching_files, joinpath(root, file))
end
end
end
return matching_files
end

# Stack environment from parent dir on top of env from this dir. This
# is so we can import ViennaRNA_jll and always have the same version
# as the parent dir.
Expand Down Expand Up @@ -37,8 +49,19 @@ open("./prologue.jl", "w") do io
println(io, "#### end prologue.jl")
end

include_dir = normpath(ViennaRNA_jll.artifact_dir, "include")
#include_dir = normpath(ViennaRNA_jll.artifact_dir, "include")
#viennarna_dir = joinpath(include_dir, "ViennaRNA")
tmpdir = mktempdir()
run(`cp -r $(normpath(ViennaRNA_jll.artifact_dir, "include")) $tmpdir/`)
include_dir = joinpath(tmpdir, "include")
viennarna_dir = joinpath(include_dir, "ViennaRNA")
patches_dir = abspath(joinpath("patches-for-headers"))
patch_files = filter(f -> endswith(f, ".patch"), readdir(patches_dir; join=true))
cd(include_dir) do
for patch in patch_files
run(pipeline(`patch -p2`, stdin=patch)) #joinpath(patches_dir, "soft_special_missing_includes.patch")))
end
end

options = load_options(joinpath(@__DIR__, "generator.toml"))
print("options =\n ")
Expand All @@ -48,6 +71,8 @@ args = get_default_args()
append!(args, [
"-I$include_dir",
"-DVRNA_DISABLE_C11_FEATURES",
# "-DVRNA_DISABLE_BACKWARD_COMPATIBILITY",
# "-DMAXALPHA=20",
])

accept_headers = [
Expand All @@ -68,10 +93,17 @@ accept_headers = [
"subopt_zuker.h",
"treedist.h",
"utils/basic.h",
"constraints/basic.h",
"constraints/hard.h",
"constraints/ligand.h",
"constraints/SHAPE.h",
"constraints/soft.h",
"constraints/soft_special.h",
]
headers = [joinpath(viennarna_dir, header) for header in accept_headers]
# there is also an experimental `detect_headers` function for auto-detecting top-level headers in the directory
# headers = detect_headers(clang_dir, args)
#headers = detect_headers(viennarna_dir, args)
#headers = find_files_matching_regex(viennarna_dir, r".*\.h")

# create context
ctx = create_context(headers, args, options)
Expand Down
14 changes: 14 additions & 0 deletions gen/patches-for-headers/soft_special_missing_includes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/src/ViennaRNA/constraints/soft_special.h b/src/ViennaRNA/constraints/soft_special.h
index 1902c930..654bc85e 100644
--- a/src/ViennaRNA/constraints/soft_special.h
+++ b/src/ViennaRNA/constraints/soft_special.h
@@ -1,6 +1,9 @@
#ifndef VIENNA_RNA_PACKAGE_CONSTRAINTS_SOFT_SPECIAL_H
#define VIENNA_RNA_PACKAGE_CONSTRAINTS_SOFT_SPECIAL_H

+#include "ViennaRNA/fold_compound.h"
+#include "ViennaRNA/model.h"
+
/**
* @file constraints/soft_special.h
* @ingroup soft_constraints, modified_bases
Loading

0 comments on commit be10f86

Please sign in to comment.