|
1 | 1 | // |
2 | 2 | // main.rs |
3 | 3 | // |
4 | | -// Copyright (C) 2022-2024 Posit Software, PBC. All rights reserved. |
| 4 | +// Copyright (C) 2022-2025 Posit Software, PBC. All rights reserved. |
5 | 5 | // |
6 | 6 | // |
7 | 7 |
|
@@ -30,31 +30,46 @@ thread_local! { |
30 | 30 |
|
31 | 31 | fn print_usage() { |
32 | 32 | println!("Ark {}, an R Kernel.", env!("CARGO_PKG_VERSION")); |
33 | | - println!( |
| 33 | + print!( |
34 | 34 | r#" |
35 | 35 | Usage: ark [OPTIONS] |
36 | 36 |
|
37 | 37 | Available options: |
38 | 38 |
|
39 | | ---connection_file FILE Start the kernel with the given JSON connection file |
40 | | - (see the Jupyter kernel documentation for details) |
41 | | --- arg1 arg2 ... Set the argument list to pass to R; defaults to |
42 | | - --interactive |
43 | | ---startup-file FILE An R file to run on session startup |
44 | | ---session-mode MODE The mode in which the session is running (console, notebook, background) |
45 | | ---no-capture-streams Do not capture stdout/stderr from R |
46 | | ---default-repos Set the default repositories to use, by name: |
47 | | - "rstudio" ('cran.rstudio.com', the default), or |
48 | | - "posit-ppm" ('packagemanager.posit.co', subject to availability), or |
49 | | - "none" (do not alter the 'repos' option in any way) |
50 | | ---repos-conf Set the default repositories to use from a configuration file |
51 | | - containing a list of named repositories (`name = url`) |
52 | | ---default-ppm-repo Set the default repositories to a custom Posit Package Manager URL. |
53 | | ---version Print the version of Ark |
54 | | ---log FILE Log to the given file (if not specified, stdout/stderr |
55 | | - will be used) |
56 | | ---install Install the kernel spec for Ark |
57 | | ---help Print this help message |
| 39 | +--connection_file FILE Start the kernel with the given JSON connection file |
| 40 | + (see the Jupyter kernel documentation for details) |
| 41 | +-- arg1 arg2 ... Set the argument list to pass to R; defaults to |
| 42 | + --interactive |
| 43 | +--startup-file FILE An R file to run on session startup |
| 44 | +--session-mode MODE The mode in which the session is running (console, notebook, background) |
| 45 | +--no-capture-streams Do not capture stdout/stderr from R |
| 46 | +--default-repos Set the default repositories to use, by name: |
| 47 | + "rstudio" ('cran.rstudio.com', the default), or |
| 48 | + "posit-ppm" ('packagemanager.posit.co', subject to availability), or |
| 49 | + "none" (do not alter the 'repos' option in any way) |
| 50 | +--repos-conf Set the default repositories to use from a configuration file |
| 51 | + containing a list of named repositories (`name = url`) |
| 52 | +--default-ppm-repo Set the default repositories to a custom Posit Package Manager URL. |
| 53 | +--version Print the version of Ark |
| 54 | +--log FILE Log to the given file (if not specified, stdout/stderr |
| 55 | + will be used) |
| 56 | +--install Install the kernel spec for Ark"# |
| 57 | + ); |
| 58 | + |
| 59 | + // Windows-specific options |
| 60 | + #[cfg(target_os = "windows")] |
| 61 | + print!( |
| 62 | + r#" |
| 63 | +--standard-dll-search-order Use the standard Windows DLL search order (including the PATH environment |
| 64 | + variable) when loading R. Useful for R installations that depend on DLLs |
| 65 | + other than those in system folders and R install folder, such as Conda. |
| 66 | + The R shared library folder must be on the PATH for this to work."# |
| 67 | + ); |
| 68 | + |
| 69 | + print!( |
| 70 | + r#" |
| 71 | +--help Print this help message |
| 72 | +
|
58 | 73 | "# |
59 | 74 | ); |
60 | 75 | } |
@@ -82,6 +97,8 @@ fn main() -> anyhow::Result<()> { |
82 | 97 | let mut has_action = false; |
83 | 98 | let mut capture_streams = true; |
84 | 99 | let mut default_repos = DefaultRepos::Auto; |
| 100 | + #[cfg(target_os = "windows")] |
| 101 | + let mut use_windows_dll_search_path = false; |
85 | 102 |
|
86 | 103 | while let Some(arg) = argv.next() { |
87 | 104 | match arg.as_str() { |
@@ -136,6 +153,8 @@ fn main() -> anyhow::Result<()> { |
136 | 153 | return Ok(()); |
137 | 154 | }, |
138 | 155 | "--no-capture-streams" => capture_streams = false, |
| 156 | + #[cfg(target_os = "windows")] |
| 157 | + "--standard-dll-search-order" => use_windows_dll_search_path = true, |
139 | 158 | "--default-repos" => { |
140 | 159 | if let Some(repos) = argv.next() { |
141 | 160 | if default_repos != DefaultRepos::Auto { |
@@ -408,6 +427,13 @@ fn main() -> anyhow::Result<()> { |
408 | 427 | // Parse the connection file |
409 | 428 | let (connection_file, registration_file) = kernel::read_connection(connection_file.as_str()); |
410 | 429 |
|
| 430 | + // Set Windows DLL search path option before starting the kernel |
| 431 | + // (this must be done before R libraries are loaded) |
| 432 | + #[cfg(target_os = "windows")] |
| 433 | + if use_windows_dll_search_path { |
| 434 | + harp::sys::library::set_use_standard_dll_search_path(true); |
| 435 | + } |
| 436 | + |
411 | 437 | // Connect the Jupyter kernel and start R. |
412 | 438 | // Does not return! |
413 | 439 | start_kernel( |
|
0 commit comments