summary refs log tree commit diff
path: root/pkgs/development/compilers/yosys/plugin-search-dirs.patch
blob: 354eeddbc2e18215d4a20ce8fa86a63ebf7d385c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
diff --git i/passes/cmds/plugin.cc w/passes/cmds/plugin.cc
index 08b4aa8c4..f00f540e9 100644
--- i/passes/cmds/plugin.cc
+++ w/passes/cmds/plugin.cc
@@ -87,15 +87,33 @@ void load_plugin(std::string filename, std::vector<std::string> aliases)
 
 			// We were unable to open the file, try to do so from the plugin directory
 			if (hdl == NULL && orig_filename.find('/') == std::string::npos) {
-				hdl = dlopen([orig_filename]() {
-					std::string new_path = proc_share_dirname() + "plugins/" + orig_filename;
+                            std::string install_dir = proc_share_dirname() + "plugins";
 
-					// Check if we need to append .so
-					if (new_path.find(".so") == std::string::npos)
-						new_path.append(".so");
+				vector<string> all_dirs;
+				all_dirs.push_back(install_dir);
 
-					return new_path;
-				}().c_str(), RTLD_LAZY|RTLD_LOCAL);
+				char* plugin_dirs = getenv("NIX_YOSYS_PLUGIN_DIRS");
+				if (plugin_dirs != NULL) {
+					std::string p(plugin_dirs), t;
+					std::stringstream ss(p);
+
+					while(std::getline(ss, t, ':')) {
+						all_dirs.push_back(t);
+					}
+				}
+
+				for (auto dir : all_dirs) {
+					hdl = dlopen([dir, orig_filename]() {
+						std::string new_path = dir + "/" + orig_filename;
+
+						// Check if we need to append .so
+						if (new_path.find(".so") == std::string::npos)
+							new_path.append(".so");
+
+						return new_path;
+					}().c_str(), RTLD_LAZY|RTLD_LOCAL);
+					if (hdl != NULL) break;
+                                }
 			}
 
 			if (hdl == NULL)