Skip to content

Commit 4191f53

Browse files
committed
Added Native C++ build and Bug Fixes
1 parent a6b74ac commit 4191f53

5 files changed

Lines changed: 805 additions & 82 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
npm-debug.log*
2525
yarn-debug.log*
2626
yarn-error.log*
27+
native-build.log
28+
npm-check.log
2729

2830
# local env files
2931
.env*.local

BUILDING.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ This project uses Node.js native addons to run scheduling algorithms in C++ for
1212

1313
## Building
1414

15-
### Automatic Build
16-
The C++ addon will be automatically built when you run:
15+
### Native Dev/Build Mode
16+
The C++ addon is built when you run native scripts:
17+
```bash
18+
npm run dev:native
19+
npm run build:native
20+
```
21+
22+
### Standard Mode (No Native Build Required)
23+
For quick development without native compilation:
1724
```bash
1825
npm run dev
1926
npm run build
@@ -42,10 +49,7 @@ If you encounter issues on Windows:
4249

4350
2. Ensure Python 3.10+ is installed and in your PATH
4451

45-
3. Set the Visual Studio version (if needed):
46-
```bash
47-
npm config set msvs_version 2022
48-
```
52+
3. Reopen your terminal after installation so toolchain environment changes are picked up.
4953

5054
## Development
5155

README.md

Lines changed: 94 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,136 @@
11
# CPU Scheduling Algorithm Simulator
22

3-
An interactive simulator for learning and testing various CPU scheduling algorithms, including First Come First Serve (FCFS), Round Robin(RR), Shortest Job First(SJF) and Shortest Remaining Time First(SRTF). This project provides a visual and dynamic way to understand scheduling algorithms, making it ideal for students and enthusiasts interested in operating systems.
4-
5-
**[View the live application here](https://scheduling-algorithm-simulator.vercel.app/)**.
6-
7-
## Table of Contents
8-
- [Overview](#overview)
9-
- [Features](#features)
10-
- [Technologies Used](#technologies-used)
11-
- [Project Structure](#project-structure)
12-
- [Installation](#installation)
13-
- [Usage](#usage)
14-
- [Contributing](#contributing)
15-
- [License](#license)
16-
17-
## Overview
18-
19-
This project is a web-based simulator for CPU scheduling algorithms. It allows users to input different processes with specific attributes (arrival time, burst time, etc.) and visualize how these processes are scheduled according to the chosen scheduling algorithm.
3+
Interactive CPU scheduling simulator with visual Gantt output, per-process metrics, and optional native C++ execution.
204

215
## Features
226

23-
- **Interactive Form**: Add and configure processes with attributes such as arrival time, burst time, and background color.
24-
- **Scheduling Algorithms**: Currently supports FCFS (First Come First Serve), RR (Round Robin), SJF (Shortest Job First) and SRTF (Shortest Remaining Time First).
25-
- **Real-Time Visualization**: Watch processes as they are scheduled and executed based on selected algorithms.
26-
- **Dark Mode Support**: Uses a ThemeProvider for seamless switching between dark and light themes.
7+
- Algorithms:
8+
- FCFS (First Come First Serve)
9+
- SJF (Shortest Job First)
10+
- SRTF (Shortest Remaining Time First)
11+
- RR (Round Robin)
12+
- Priority Non-Preemptive
13+
- Priority Preemptive
14+
- Process fields:
15+
- Arrival Time
16+
- Burst Time
17+
- Priority
18+
- Color
19+
- Global scheduling controls:
20+
- Time Quantum (RR)
21+
- Context Switching Time (applied across algorithms)
22+
- Visual and metrics output:
23+
- Gantt chart with Idle and CS (context switch) blocks
24+
- Completion Time, Waiting Time, Turnaround Time
25+
- Average metrics, throughput, CPU utilization
26+
- Runtime strategy:
27+
- Native C++ addon used when available
28+
- TypeScript fallback when native addon is unavailable
29+
30+
## Tech Stack
31+
32+
- Next.js 14
33+
- React + TypeScript
34+
- Tailwind CSS
35+
- React Hook Form + Zod
36+
- node-gyp + C++ (optional native path)
37+
38+
## Project Structure
39+
40+
```text
41+
app/
42+
api/schedule/route.ts # Server-side scheduling endpoint (Node runtime)
43+
components/
44+
MainForm.tsx # Inputs, run action, and results wiring
45+
GanttChart.tsx # Timeline visualization
46+
SummaryTable.tsx # CT / WT / TAT table
47+
SummaryStatistics.tsx # Averages and utilization
48+
cpp/
49+
include/ # C++ headers
50+
src/ # C++ algorithm implementations + binding.cc
51+
lib/
52+
scheduling-native.ts # Native loader with TS fallback
53+
binding.gyp # Native build config
54+
```
2755

28-
## Technologies Used
56+
## Prerequisites
2957

30-
- **Next.js**: Frontend framework for React applications.
31-
- **TypeScript**: Provides type safety and ensures code robustness.
32-
- **Tailwind CSS**: Utility-first CSS framework for styling.
33-
- **Zod**: For form validation schemas.
34-
- **React Hook Form**: Handles form state and validation.
35-
- **Custom Components**: Built-in components like `GradientPicker` for user-friendly UI interactions.
58+
- Node.js 20+
59+
- npm
60+
- Python 3.10+
3661

62+
For native C++ build on Windows:
63+
- Visual Studio Build Tools 2022 (Desktop C++ workload)
3764

3865
## Installation
3966

40-
To set up the project locally, ensure you have [Node.js](https://nodejs.org/en/download/) and [Yarn](https://classic.yarnpkg.com/en/docs/install/) or [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) installed.
41-
42-
### Step 1: Clone the Repository
43-
4467
```bash
45-
git clone https://github.com/kautilyadevaraj/SchedulingAlgorithmSimulator
46-
cd scheduling-algorithm-simulator
68+
git clone https://github.com/kautilyadevaraj/SchedulingAlgorithmSimulator.git
69+
cd SchedulingAlgorithmSimulator
70+
npm install
4771
```
4872

49-
### Step 2: Install Dependencies
73+
## Run Modes
5074

51-
Run the following command to install the necessary dependencies.
52-
#### Using Yarn
53-
```bash
54-
yarn install
55-
```
75+
Standard mode (no native build required):
5676

57-
#### OR using npm
5877
```bash
59-
npm install
78+
npm run dev
6079
```
6180

62-
### Step 3: Environment Setup
81+
Native mode (build C++ first, then start):
6382

64-
No environment variables are required for this project in its current state. However, if you extend the project with a backend API or database, create a .env.local file in the root directory for environment variables.
83+
```bash
84+
npm run dev:native
85+
```
6586

66-
### Step 4: Run the Development Server
87+
## Native Build Commands
6788

68-
Start the development server by running:
69-
#### Using Yarn
7089
```bash
71-
yarn dev
90+
npm run build-native
91+
npm run clean-native
7292
```
7393

74-
#### OR using npm
75-
```bash
76-
npm run dev
94+
If native build succeeds, addon output is generated at:
95+
96+
```text
97+
build/Release/scheduling_algorithms.node
7798
```
78-
This will start the Next.js development server at [http://localhost:3000](http://localhost:3000). You can view the project in your browser by navigating to this address.
7999

80-
## Step 5: Build for Production (Optional)
100+
## Production Build
101+
102+
Standard production build:
81103

82-
If you want to build the project for production, run:
83-
#### Using Yarn
84104
```bash
85-
yarn build
105+
npm run build
106+
npm run start
86107
```
87108

88-
#### OR using npm
109+
Native production build:
110+
89111
```bash
90-
npm run build
112+
npm run build:native
113+
npm run start
91114
```
92-
This will create an optimized production build in the .next folder.
93115

94-
## Usage
116+
## Troubleshooting
95117

96-
1. Add Processes: Use the form to add processes with specific arrival times, burst times, and custom background colors.
97-
2. Select Algorithm: Choose a scheduling algorithm from the provided options (e.g., SRTF, FCFS).
98-
3. Run Simulation: The simulator will display the scheduling results in a real-time animation.
118+
- Native addon missing warning:
119+
- App still runs using TypeScript fallback.
120+
- Windows node-gyp issues:
121+
- Ensure VS 2022 Build Tools are installed and complete.
122+
- Reopen terminal after installation.
123+
- Run `npm run clean-native` then `npm run build-native`.
124+
- Node 24 build requirement:
125+
- C++20 is required by Node headers; this repository is configured accordingly in `binding.gyp`.
99126

100127
## Contributing
101128

102-
We welcome contributions! To contribute to this project, please follow these steps:
103-
104129
1. Fork the repository.
105-
2. Create a new branch (git checkout -b feature-branch-name).
106-
3. Make your changes.
107-
4. Commit your changes (git commit -m 'Add some feature').
108-
5. Push to the branch (git push origin feature-branch-name).
109-
6. Open a Pull Request.
110-
111-
For major changes, please open an issue first to discuss what you would like to change.
130+
2. Create a branch.
131+
3. Commit focused changes.
132+
4. Open a pull request.
112133

113134
## License
114135

115-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
136+
MIT. See `LICENSE`.

binding.gyp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@
1818
'conditions': [
1919
['OS=="win"', {
2020
'msbuild_toolset': 'v143',
21-
'msbuild_settings': {
21+
'msvs_settings': {
2222
'VCCLCompilerTool': {
23-
'RuntimeLibrary': '1'
23+
'RuntimeLibrary': '1',
24+
'AdditionalOptions': [
25+
'/std:c++20'
26+
]
2427
}
2528
}
2629
}],
2730
['OS=="unix"', {
28-
'cflags': ['-Wall', '-Wextra', '-O2']
31+
'cflags': ['-Wall', '-Wextra', '-O2'],
32+
'cflags_cc': ['-std=c++20']
2933
}]
3034
]
3135
}

0 commit comments

Comments
 (0)