latest pushes
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# Bellande Rust Executable
|
# Bellande Rust Executable
|
||||||
|
|
||||||
## Bellande Rust Executable is a library that makes rust code into an executable (BRE) library
|
## Bellande Rust Executable is a library that makes rust code into an executable (BRE) library
|
||||||
- "-d", "--dep-file", required=True, help="Path to the dependencies file (dependencies.txt) will soon be dependencies.bellande"
|
- "-d", "--dep-file", required=True, help="Path to the dependencies file (dependencies.bellande)"
|
||||||
- "-s", "--src-dir", required=True, help="Source directory containing Rust files"
|
- "-s", "--src-dir", required=True, help="Source directory containing Rust files"
|
||||||
- "-m", "--main-file", required=True, help="Main Rust file name (e.g., main.rs)"
|
- "-m", "--main-file", required=True, help="Main Rust file name (e.g., main.rs)"
|
||||||
- "-o", "--output", required=True, help="Output path for the compiled executable"
|
- "-o", "--output", required=True, help="Output path for the compiled executable"
|
||||||
@@ -17,14 +17,11 @@
|
|||||||
|
|
||||||
```
|
```
|
||||||
Name: bellande_rust_executable
|
Name: bellande_rust_executable
|
||||||
Version: 0.1.0
|
|
||||||
Summary: File type Formats
|
Summary: File type Formats
|
||||||
Home-page: github.com/RonaldsonBellande/bellande_rust_executable
|
Home-page: github.com/RonaldsonBellande/bellande_rust_executable
|
||||||
Author: Ronaldson Bellande
|
Author: Ronaldson Bellande
|
||||||
Author-email: ronaldsonbellande@gmail.com
|
Author-email: ronaldsonbellande@gmail.com
|
||||||
License: GNU General Public License v3.0
|
License: GNU General Public License v3.0
|
||||||
Requires: numpy
|
|
||||||
Required-by:
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
@@ -20,6 +20,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import argparse
|
import argparse
|
||||||
import toml
|
import toml
|
||||||
|
from bellande_format import Bellande_Format
|
||||||
|
|
||||||
def ensure_directory(path):
|
def ensure_directory(path):
|
||||||
"""Ensure a directory exists and create one if it does not"""
|
"""Ensure a directory exists and create one if it does not"""
|
||||||
@@ -52,7 +53,6 @@ def create_cargo_toml(project_dir, main_file, binary_name):
|
|||||||
'dependencies': {}
|
'dependencies': {}
|
||||||
}
|
}
|
||||||
|
|
||||||
# If the main file isn't main.rs, we need to specify the path
|
|
||||||
if main_file != 'main.rs':
|
if main_file != 'main.rs':
|
||||||
cargo_config['bin'] = [{
|
cargo_config['bin'] = [{
|
||||||
'name': binary_name,
|
'name': binary_name,
|
||||||
@@ -64,19 +64,22 @@ def create_cargo_toml(project_dir, main_file, binary_name):
|
|||||||
toml.dump(cargo_config, f)
|
toml.dump(cargo_config, f)
|
||||||
|
|
||||||
def parse_dependencies(dep_file):
|
def parse_dependencies(dep_file):
|
||||||
"""Parse dependencies from the specified dependencies file."""
|
"""Parse dependencies from the specified .bellande file using Bellande_Format."""
|
||||||
dependencies = {}
|
bellande_parser = Bellande_Format()
|
||||||
if os.path.exists(dep_file):
|
parsed_data = bellande_parser.parse_bellande(dep_file)
|
||||||
with open(dep_file, 'r') as file:
|
|
||||||
for line in file:
|
# Convert the string representation to a Python dictionary
|
||||||
line = line.strip()
|
dependencies = eval(parsed_data)
|
||||||
if line and not line.startswith('#'):
|
|
||||||
try:
|
# Process the dependencies to match Cargo.toml format
|
||||||
name, version = line.split('=')
|
processed_dependencies = {}
|
||||||
dependencies[name.strip()] = version.strip().strip('"')
|
for name, value in dependencies.items():
|
||||||
except ValueError:
|
if isinstance(value, str):
|
||||||
print(f"Warning: Skipping invalid dependency line: {line}")
|
processed_dependencies[name] = value
|
||||||
return dependencies
|
elif isinstance(value, dict):
|
||||||
|
processed_dependencies[name] = value
|
||||||
|
|
||||||
|
return processed_dependencies
|
||||||
|
|
||||||
def update_cargo_toml_dependencies(project_dir, dependencies):
|
def update_cargo_toml_dependencies(project_dir, dependencies):
|
||||||
"""Update the dependencies in Cargo.toml."""
|
"""Update the dependencies in Cargo.toml."""
|
||||||
@@ -95,18 +98,11 @@ def build_project(project_dir, output_path, binary_name):
|
|||||||
result = subprocess.run(cargo_command, cwd=project_dir, capture_output=True, text=True)
|
result = subprocess.run(cargo_command, cwd=project_dir, capture_output=True, text=True)
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
# Determine the correct executable name based on platform
|
exe_extension = '.exe' if os.name == 'nt' else ''
|
||||||
if os.name == 'nt': # Windows
|
|
||||||
exe_extension = '.exe'
|
|
||||||
else: # Unix-like systems
|
|
||||||
exe_extension = ''
|
|
||||||
|
|
||||||
# Copy the built executable to the specified output location
|
|
||||||
built_exe = os.path.join(project_dir, 'target', 'release', f"{binary_name}{exe_extension}")
|
built_exe = os.path.join(project_dir, 'target', 'release', f"{binary_name}{exe_extension}")
|
||||||
ensure_directory(os.path.dirname(output_path))
|
ensure_directory(os.path.dirname(output_path))
|
||||||
shutil.copy2(built_exe, output_path)
|
shutil.copy2(built_exe, output_path)
|
||||||
|
|
||||||
# Make the output file executable on Unix-like systems
|
|
||||||
if os.name != 'nt':
|
if os.name != 'nt':
|
||||||
os.chmod(output_path, 0o755)
|
os.chmod(output_path, 0o755)
|
||||||
|
|
||||||
@@ -119,17 +115,14 @@ def build_project(project_dir, output_path, binary_name):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Universal Rust Executable Builder")
|
parser = argparse.ArgumentParser(description="Universal Rust Executable Builder")
|
||||||
parser.add_argument("-d", "--dep-file", required=True, help="Path to the dependencies file")
|
parser.add_argument("-d", "--dep-file", required=True, help="Path to the .bellande dependencies file")
|
||||||
parser.add_argument("-s", "--src-dir", required=True, help="Source directory containing Rust files")
|
parser.add_argument("-s", "--src-dir", required=True, help="Source directory containing Rust files")
|
||||||
parser.add_argument("-m", "--main-file", required=True, help="Main Rust file name (e.g., main.rs)")
|
parser.add_argument("-m", "--main-file", required=True, help="Main Rust file name (e.g., main.rs)")
|
||||||
parser.add_argument("-o", "--output", required=True, help="Output path for the compiled executable")
|
parser.add_argument("-o", "--output", required=True, help="Output path for the compiled executable")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Extract binary name from the file name (removing .rs extension)
|
|
||||||
binary_name = os.path.splitext(args.main_file)[0]
|
binary_name = os.path.splitext(args.main_file)[0]
|
||||||
|
|
||||||
# Create unique build directory based on binary name
|
|
||||||
build_dir = f"build_{binary_name}"
|
build_dir = f"build_{binary_name}"
|
||||||
ensure_directory(build_dir)
|
ensure_directory(build_dir)
|
||||||
|
|
||||||
@@ -137,17 +130,11 @@ def main():
|
|||||||
copy_source_files(args.src_dir, build_dir)
|
copy_source_files(args.src_dir, build_dir)
|
||||||
create_cargo_toml(build_dir, args.main_file, binary_name)
|
create_cargo_toml(build_dir, args.main_file, binary_name)
|
||||||
|
|
||||||
# Parse and update dependencies
|
|
||||||
dependencies = parse_dependencies(args.dep_file)
|
dependencies = parse_dependencies(args.dep_file)
|
||||||
update_cargo_toml_dependencies(build_dir, dependencies)
|
update_cargo_toml_dependencies(build_dir, dependencies)
|
||||||
|
|
||||||
# Determine the correct output path based on platform
|
output_path = f"{args.output}.exe" if os.name == 'nt' else args.output
|
||||||
if os.name == 'nt': # Windows
|
|
||||||
output_path = f"{args.output}.exe"
|
|
||||||
else: # Unix-like systems
|
|
||||||
output_path = args.output
|
|
||||||
|
|
||||||
# Build the project
|
|
||||||
if build_project(build_dir, output_path, binary_name):
|
if build_project(build_dir, output_path, binary_name):
|
||||||
print(f"Successfully built and copied to {output_path}")
|
print(f"Successfully built and copied to {output_path}")
|
||||||
return 0
|
return 0
|
||||||
@@ -156,7 +143,6 @@ def main():
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Clean up build directory
|
|
||||||
shutil.rmtree(build_dir, ignore_errors=True)
|
shutil.rmtree(build_dir, ignore_errors=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user