Publishing my project with a different name than my working directory

I tried publishing my project to crates.io so that potential users/collaborators can see its documentation. The problem is that the name cargo gave to it is the same as the working directory I’m currently using. So I tried changing the name field in my `Cargo.toml` file to the actual name of the project, and then the compiler had trouble finding some of the modules in the project. So, how can I publish my crate using the correct name (which is not the name of the working directory) without crashing the compiler?

Here’s a copy of my Cargo.toml file:

[package]

name = "question_bank_creator"
#name = "rebuild7"   // This is the name of the working directory

version = "0.29.8"
authors = ["John T. Reagan"]
license = "GPL-3.0-or-later"
readme = "README.md"
edition = "2021"
repository = "https://github.com/jtreagan/Question-Bank-Creator/tree/master"

description = "This program is targeted at teachers & homeschool parents and is especially useful for teaching math.  It allows the construction of test/worksheet/quiz questions that contain dynamic content.  The teacher can create variables that generate values/strings using random or pseudo-random criteria set by the user.  Once constructed, the question is stored in a file (or 'question bank') for later access as needed.  Teachers can also make the program/questions available to students for student directed practice."

[dependencies]
#Standard crates
rand = "0.8.5"

# Non-standard crates
num-traits = "0.2.19"
serde_json = "1.0.120"
serde = { version = "1.0.204", features = ["derive"] }
fltk = { version = "^1.5.5", features = ["fltk-bundled"] }

# Reagan created crates
lib_myfltk = "0.1.4"
#lib_myfltk = {path = "/home/jtreagan/programming/mine/lib_myfltk"}
lib_utils = "0.1.3"
lib_file = "0.1.2"
```

Thanks!

There is no necessary relationship between the package.name and the name of the directory it is in, and your Cargo.toml doesn't contain anything that would cause there to be a problem.

So, it is not clear what “the compiler had trouble finding some of the modules in the project” means. Please share the full output from the command you tried that is failing.

1 Like

The repo for this project is here (inferred from past threads): GitHub - jtreagan/Question-Bank-Creator: This program is targeted at teachers & homeschool parents and is especially useful for teaching math and science, although it also can be useful as an aide in the teaching of other disciplines.

I think the question relates to using the crate name from main.rs. It's currently rebuild7, and when it is changed in Cargo.toml it also needs to be fixed in main.rs.

2 Likes

This turned out to be the problem. I had the following at the top of my main.rs file:

use rebuild7::{menus::*, misc::*};
use rebuild7::{APP_FLTK, WIDGETS};
use rebuild7::{Wdgts};

It was there so I could access modules, global variables, and structs that were part of the project’s lib.rs file. So, when I changed the name field of my Cargo.toml, I needed to change the name used in these use statements. So, I learned something about how the compiler interacts with the code files. Here are the new lines that work:

use question_bank_creator::{menus::*, misc::*};
use question_bank_creator::{APP_FLTK, WIDGETS};
use question_bank_creator::{Wdgts};

And the published version is here.

Thanks for responding. I was about to paste a whole bunch of compiler error output for you, but decided to check out @parasyte’s suggestion first, just in case, and it worked. So, you didn’t have to wade through all that text. Thanks again for your help.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.