Skip to content

Commit 08cc9a0

Browse files
committed
fix: Only support llvm 19 and 20
1 parent 41be26d commit 08cc9a0

File tree

1 file changed

+160
-155
lines changed

1 file changed

+160
-155
lines changed

rune/vendor/llvm/config/discover.ml

Lines changed: 160 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -2,175 +2,180 @@ module C = Configurator.V1
22

33
let get_llvm_config c =
44
(* Try different llvm-config names in order of preference *)
5-
let possible_names = [
6-
"llvm-config-20";
7-
"llvm-config-19";
8-
"llvm-config-18";
9-
"llvm-config-17";
10-
"llvm-config-16";
11-
"llvm-config-15";
12-
"llvm-config";
13-
] in
14-
5+
let possible_names = [ "llvm-config-20"; "llvm-config-19" ] in
6+
157
let rec find_llvm_config = function
168
| [] -> None
179
| cmd :: rest ->
18-
if C.Process.run_ok c cmd ["--version"] then Some cmd
10+
if C.Process.run_ok c cmd [ "--version" ] then Some cmd
1911
else find_llvm_config rest
2012
in
21-
13+
2214
match find_llvm_config possible_names with
23-
| None ->
15+
| None ->
2416
(* Try homebrew paths *)
25-
let brew_paths = [
26-
"/opt/homebrew/opt/llvm/bin/llvm-config";
27-
"/opt/homebrew/opt/llvm@20/bin/llvm-config";
28-
"/opt/homebrew/opt/llvm@19/bin/llvm-config";
29-
"/opt/homebrew/opt/llvm@18/bin/llvm-config";
30-
"/usr/local/opt/llvm/bin/llvm-config";
31-
"/usr/local/opt/llvm@20/bin/llvm-config";
32-
"/usr/local/opt/llvm@19/bin/llvm-config";
33-
] in
17+
let brew_paths =
18+
[
19+
"/opt/homebrew/opt/llvm/bin/llvm-config";
20+
"/opt/homebrew/opt/llvm@20/bin/llvm-config";
21+
"/opt/homebrew/opt/llvm@19/bin/llvm-config";
22+
"/opt/homebrew/opt/llvm@18/bin/llvm-config";
23+
"/usr/local/opt/llvm/bin/llvm-config";
24+
"/usr/local/opt/llvm@20/bin/llvm-config";
25+
"/usr/local/opt/llvm@19/bin/llvm-config";
26+
]
27+
in
3428
find_llvm_config brew_paths
3529
| Some cmd -> Some cmd
3630

3731
let run_capture_opt c cmd args =
3832
(* Use run_ok to check if command succeeds without logging errors *)
3933
if C.Process.run_ok c cmd args then
4034
Some (C.Process.run_capture_exn c cmd args)
41-
else
42-
None
35+
else None
4336

4437
let () =
4538
C.main ~name:"llvm-config" (fun c ->
46-
match get_llvm_config c with
47-
| None ->
48-
C.die "Could not find llvm-config. Please install LLVM and ensure llvm-config is in your PATH."
49-
| Some llvm_config ->
50-
let version =
51-
C.Process.run_capture_exn c llvm_config ["--version"]
52-
|> String.trim
53-
in
54-
Printf.printf "Found LLVM version %s using %s\n%!" version llvm_config;
55-
56-
(* Get compiler flags *)
57-
let cflags =
58-
C.Process.run_capture_exn c llvm_config ["--cflags"]
59-
|> String.trim
60-
|> String.split_on_char ' '
61-
|> List.filter (fun s -> String.length s > 0)
62-
in
63-
64-
(* Add -fPIC on Linux and BSD systems for position-independent code.
65-
This is required when building shared libraries on x86-64 Linux to avoid
66-
relocation errors like "relocation R_X86_64_32 against `.data' can not be
67-
used when making a shared object" *)
68-
let cflags =
69-
match C.ocaml_config_var c "system" with
70-
| Some "linux" | Some "freebsd" | Some "netbsd" | Some "openbsd"
71-
| Some "dragonfly" | Some "gnu" -> "-fPIC" :: cflags
72-
| _ -> cflags
73-
in
74-
75-
(* Get linker flags *)
76-
let ldflags =
77-
C.Process.run_capture_exn c llvm_config ["--ldflags"]
78-
|> String.trim
79-
|> String.split_on_char ' '
80-
|> List.filter (fun s -> String.length s > 0)
81-
in
82-
83-
(* Get libraries for different components *)
84-
let libs_core =
85-
C.Process.run_capture_exn c llvm_config ["--libs"; "core"; "support"]
86-
|> String.trim
87-
|> String.split_on_char ' '
88-
|> List.filter (fun s -> String.length s > 0)
89-
in
90-
91-
let libs_executionengine =
92-
C.Process.run_capture_exn c llvm_config
93-
["--libs"; "executionengine"; "mcjit"; "native"]
94-
|> String.trim
95-
|> String.split_on_char ' '
96-
|> List.filter (fun s -> String.length s > 0)
97-
in
98-
99-
let libs_analysis =
100-
C.Process.run_capture_exn c llvm_config ["--libs"; "analysis"]
101-
|> String.trim
102-
|> String.split_on_char ' '
103-
|> List.filter (fun s -> String.length s > 0)
104-
in
105-
106-
let libs_target =
107-
C.Process.run_capture_exn c llvm_config ["--libs"; "target"; "asmparser"; "asmprinter"]
108-
|> String.trim
109-
|> String.split_on_char ' '
110-
|> List.filter (fun s -> String.length s > 0)
111-
in
112-
113-
let libs_bitreader =
114-
match run_capture_opt c llvm_config ["--libs"; "bitreader"] with
115-
| Some output ->
116-
output |> String.trim |> String.split_on_char ' '
117-
|> List.filter (fun s -> String.length s > 0)
118-
| None -> []
119-
in
120-
121-
let libs_bitwriter =
122-
match run_capture_opt c llvm_config ["--libs"; "bitwriter"] with
123-
| Some output ->
124-
output |> String.trim |> String.split_on_char ' '
125-
|> List.filter (fun s -> String.length s > 0)
126-
| None -> []
127-
in
128-
129-
let libs_transforms =
130-
(* Try different transform library names as they vary by LLVM version *)
131-
match run_capture_opt c llvm_config ["--libs"; "transformutils"; "scalaropt"; "ipo"; "vectorize"] with
132-
| Some output ->
133-
output |> String.trim |> String.split_on_char ' '
134-
|> List.filter (fun s -> String.length s > 0)
135-
| None ->
136-
(* Try newer LLVM names *)
137-
match run_capture_opt c llvm_config ["--libs"; "passes"; "transforms"] with
138-
| Some output ->
139-
output |> String.trim |> String.split_on_char ' '
140-
|> List.filter (fun s -> String.length s > 0)
141-
| None -> []
142-
in
143-
144-
let libs_all =
145-
C.Process.run_capture_exn c llvm_config ["--libs"; "all"]
146-
|> String.trim
147-
|> String.split_on_char ' '
148-
|> List.filter (fun s -> String.length s > 0)
149-
in
150-
151-
(* Write sexp files for each library *)
152-
C.Flags.write_sexp "llvm_cflags.sexp" cflags;
153-
C.Flags.write_sexp "llvm_libs_core.sexp" (ldflags @ libs_core);
154-
C.Flags.write_sexp "llvm_libs_executionengine.sexp" (ldflags @ libs_executionengine);
155-
C.Flags.write_sexp "llvm_libs_analysis.sexp" (ldflags @ libs_analysis);
156-
C.Flags.write_sexp "llvm_libs_target.sexp" (ldflags @ libs_target);
157-
C.Flags.write_sexp "llvm_libs_bitreader.sexp" (ldflags @ libs_bitreader);
158-
C.Flags.write_sexp "llvm_libs_bitwriter.sexp" (ldflags @ libs_bitwriter);
159-
C.Flags.write_sexp "llvm_libs_transforms.sexp" (ldflags @ libs_transforms);
160-
C.Flags.write_sexp "llvm_libs_all.sexp" (ldflags @ libs_all);
161-
162-
(* Generate version file for conditional compilation *)
163-
let version_parts = String.split_on_char '.' version in
164-
let version_major =
165-
match version_parts with
166-
| major :: _ -> (try int_of_string major with _ -> 0)
167-
| [] -> 0
168-
in
169-
170-
let version_file = open_out "llvm_version.ml" in
171-
Printf.fprintf version_file "(* Auto-generated by discover.ml *)\n";
172-
Printf.fprintf version_file "let major = %d\n" version_major;
173-
Printf.fprintf version_file "let version = \"%s\"\n" version;
174-
Printf.fprintf version_file "let llvm_config = \"%s\"\n" llvm_config;
175-
close_out version_file
176-
)
39+
match get_llvm_config c with
40+
| None ->
41+
C.die
42+
"Could not find llvm-config. Please install LLVM and ensure \
43+
llvm-config is in your PATH."
44+
| Some llvm_config ->
45+
let version =
46+
C.Process.run_capture_exn c llvm_config [ "--version" ]
47+
|> String.trim
48+
in
49+
Printf.printf "Found LLVM version %s using %s\n%!" version llvm_config;
50+
51+
(* Get compiler flags *)
52+
let cflags =
53+
C.Process.run_capture_exn c llvm_config [ "--cflags" ]
54+
|> String.trim |> String.split_on_char ' '
55+
|> List.filter (fun s -> String.length s > 0)
56+
in
57+
58+
(* Add -fPIC on Linux and BSD systems for position-independent code.
59+
This is required when building shared libraries on x86-64 Linux to
60+
avoid relocation errors like "relocation R_X86_64_32 against
61+
`.data' can not be used when making a shared object" *)
62+
let cflags =
63+
match C.ocaml_config_var c "system" with
64+
| Some "linux"
65+
| Some "freebsd"
66+
| Some "netbsd"
67+
| Some "openbsd"
68+
| Some "dragonfly"
69+
| Some "gnu" ->
70+
"-fPIC" :: cflags
71+
| _ -> cflags
72+
in
73+
74+
(* Get linker flags *)
75+
let ldflags =
76+
C.Process.run_capture_exn c llvm_config [ "--ldflags" ]
77+
|> String.trim |> String.split_on_char ' '
78+
|> List.filter (fun s -> String.length s > 0)
79+
in
80+
81+
(* Get libraries for different components *)
82+
let libs_core =
83+
C.Process.run_capture_exn c llvm_config
84+
[ "--libs"; "core"; "support" ]
85+
|> String.trim |> String.split_on_char ' '
86+
|> List.filter (fun s -> String.length s > 0)
87+
in
88+
89+
let libs_executionengine =
90+
C.Process.run_capture_exn c llvm_config
91+
[ "--libs"; "executionengine"; "mcjit"; "native" ]
92+
|> String.trim |> String.split_on_char ' '
93+
|> List.filter (fun s -> String.length s > 0)
94+
in
95+
96+
let libs_analysis =
97+
C.Process.run_capture_exn c llvm_config [ "--libs"; "analysis" ]
98+
|> String.trim |> String.split_on_char ' '
99+
|> List.filter (fun s -> String.length s > 0)
100+
in
101+
102+
let libs_target =
103+
C.Process.run_capture_exn c llvm_config
104+
[ "--libs"; "target"; "asmparser"; "asmprinter" ]
105+
|> String.trim |> String.split_on_char ' '
106+
|> List.filter (fun s -> String.length s > 0)
107+
in
108+
109+
let libs_bitreader =
110+
match run_capture_opt c llvm_config [ "--libs"; "bitreader" ] with
111+
| Some output ->
112+
output |> String.trim |> String.split_on_char ' '
113+
|> List.filter (fun s -> String.length s > 0)
114+
| None -> []
115+
in
116+
117+
let libs_bitwriter =
118+
match run_capture_opt c llvm_config [ "--libs"; "bitwriter" ] with
119+
| Some output ->
120+
output |> String.trim |> String.split_on_char ' '
121+
|> List.filter (fun s -> String.length s > 0)
122+
| None -> []
123+
in
124+
125+
let libs_transforms =
126+
(* Try different transform library names as they vary by LLVM
127+
version *)
128+
match
129+
run_capture_opt c llvm_config
130+
[ "--libs"; "transformutils"; "scalaropt"; "ipo"; "vectorize" ]
131+
with
132+
| Some output ->
133+
output |> String.trim |> String.split_on_char ' '
134+
|> List.filter (fun s -> String.length s > 0)
135+
| None -> (
136+
(* Try newer LLVM names *)
137+
match
138+
run_capture_opt c llvm_config
139+
[ "--libs"; "passes"; "transforms" ]
140+
with
141+
| Some output ->
142+
output |> String.trim |> String.split_on_char ' '
143+
|> List.filter (fun s -> String.length s > 0)
144+
| None -> [])
145+
in
146+
147+
let libs_all =
148+
C.Process.run_capture_exn c llvm_config [ "--libs"; "all" ]
149+
|> String.trim |> String.split_on_char ' '
150+
|> List.filter (fun s -> String.length s > 0)
151+
in
152+
153+
(* Write sexp files for each library *)
154+
C.Flags.write_sexp "llvm_cflags.sexp" cflags;
155+
C.Flags.write_sexp "llvm_libs_core.sexp" (ldflags @ libs_core);
156+
C.Flags.write_sexp "llvm_libs_executionengine.sexp"
157+
(ldflags @ libs_executionengine);
158+
C.Flags.write_sexp "llvm_libs_analysis.sexp" (ldflags @ libs_analysis);
159+
C.Flags.write_sexp "llvm_libs_target.sexp" (ldflags @ libs_target);
160+
C.Flags.write_sexp "llvm_libs_bitreader.sexp"
161+
(ldflags @ libs_bitreader);
162+
C.Flags.write_sexp "llvm_libs_bitwriter.sexp"
163+
(ldflags @ libs_bitwriter);
164+
C.Flags.write_sexp "llvm_libs_transforms.sexp"
165+
(ldflags @ libs_transforms);
166+
C.Flags.write_sexp "llvm_libs_all.sexp" (ldflags @ libs_all);
167+
168+
(* Generate version file for conditional compilation *)
169+
let version_parts = String.split_on_char '.' version in
170+
let version_major =
171+
match version_parts with
172+
| major :: _ -> ( try int_of_string major with _ -> 0)
173+
| [] -> 0
174+
in
175+
176+
let version_file = open_out "llvm_version.ml" in
177+
Printf.fprintf version_file "(* Auto-generated by discover.ml *)\n";
178+
Printf.fprintf version_file "let major = %d\n" version_major;
179+
Printf.fprintf version_file "let version = \"%s\"\n" version;
180+
Printf.fprintf version_file "let llvm_config = \"%s\"\n" llvm_config;
181+
close_out version_file)

0 commit comments

Comments
 (0)