improved rust compile function to set its working directory